Skip to content

Fix location area encounters lookup assuming contiguous ids#1608

Merged
Naramsim merged 2 commits into
PokeAPI:masterfrom
santichausis:fix/location-area-encounters-version-index
Jul 18, 2026
Merged

Fix location area encounters lookup assuming contiguous ids#1608
Naramsim merged 2 commits into
PokeAPI:masterfrom
santichausis:fix/location-area-encounters-version-index

Conversation

@santichausis

Copy link
Copy Markdown
Contributor

Problem

Same root cause as #1567 (fixed in #1603): LocationAreaDetailSerializer.get_encounters looks up Version summaries by list position (id - 1), assuming the table forms a contiguous 1-indexed sequence.

Any gap in the Version table (e.g. a deleted row) causes the wrong version to be returned for an encounter, or raises an IndexError.

This was originally reported in #1313 and attempted in #1314, which was closed without merging.

Fix

Same approach as #1603: build a dict keyed by the actual id instead of relying on list position.

Test plan

  • Added test_location_area_encounters_with_non_contiguous_version_ids, which creates and deletes a Version to force a gap, then asserts the location-area endpoint still returns the correct version.
  • Verified this test reproduces the IndexError against the old code and passes with the fix.
  • manage.py test pokemon_v2 passes (56 tests).
  • black --check passes.

Same issue as PokeAPI#1567 / PR PokeAPI#1603 (previously fixed in
get_pokemon_moves): LocationAreaDetailSerializer.get_encounters looked
up Version summaries by list position (id - 1), assuming ids form a
contiguous 1-indexed sequence. Any gap in the Version table (e.g. a
deleted row) causes the wrong version to be returned, or an
IndexError.

This is the same root cause reported in PokeAPI#1313 and previously
attempted in PR PokeAPI#1314 (closed, unmerged).
@Naramsim

Copy link
Copy Markdown
Member

Thanks a lot!

@Naramsim
Naramsim merged commit 9be81dd into PokeAPI:master Jul 18, 2026
16 of 18 checks passed
@pokeapi-machine-user

Copy link
Copy Markdown

A PokeAPI/api-data refresh has started. In ~45 minutes the staging branch of PokeAPI/api-data will be pushed with the new generated data.

The staging branch will be deployed in our staging environment and the entire API will be ready to review.

A Pull Request (master<-staging) will be also created at PokeAPI/api-data and assigned to the PokeAPI Core team to be reviewed. If approved and merged new data will soon be available worldwide at pokeapi.co.

@pokeapi-machine-user

Copy link
Copy Markdown

The updater script has finished its job and has now opened a Pull Request towards PokeAPI/api-data with the updated data.

The Pull Request can be seen deployed in our staging environment when CircleCI deploy will be finished (check the start time of the last build).

Naramsim pushed a commit to PokeAPI/api-data that referenced this pull request Jul 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants