Fix location area encounters lookup assuming contiguous ids#1608
Merged
Naramsim merged 2 commits intoJul 18, 2026
Merged
Conversation
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
approved these changes
Jul 18, 2026
Member
|
Thanks a lot! |
|
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. |
pokeapi-machine-user
added a commit
to PokeAPI/api-data
that referenced
this pull request
Jul 18, 2026
|
The updater script has finished its job and has now opened a Pull Request towards PokeAPI/api-data with the updated data. |
Naramsim
pushed a commit
to PokeAPI/api-data
that referenced
this pull request
Jul 18, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Same root cause as #1567 (fixed in #1603):
LocationAreaDetailSerializer.get_encounterslooks upVersionsummaries by list position (id - 1), assuming the table forms a contiguous 1-indexed sequence.Any gap in the
Versiontable (e.g. a deleted row) causes the wrong version to be returned for an encounter, or raises anIndexError.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
idinstead of relying on list position.Test plan
test_location_area_encounters_with_non_contiguous_version_ids, which creates and deletes aVersionto force a gap, then asserts thelocation-areaendpoint still returns the correct version.IndexErroragainst the old code and passes with the fix.manage.py test pokemon_v2passes (56 tests).black --checkpasses.