Skip to content

Fix location area encounters lookup assuming contiguous ids#1608

Open
santichausis wants to merge 1 commit into
PokeAPI:masterfrom
santichausis:fix/location-area-encounters-version-index
Open

Fix location area encounters lookup assuming contiguous ids#1608
santichausis wants to merge 1 commit 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).
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.

1 participant