Move effect build order is incorrect (fixes #1663) - #1674
Open
Atakan-24 wants to merge 5 commits into
Open
Conversation
…okeAPI#1663) PR PokeAPI#1637 replaced the per-row MoveEffect lookup with a precomputed set of existing effect ids, but declared that set far below the MoveEffect build step and only used it for MoveChange. Move.move_effect_id was still assigned straight from moves.csv without checking that the effect exists. - add resolve_existing_id() helper that maps a CSV FK column to an id only if that id was actually built, else None - compute existing_effect_ids immediately after MoveEffect is built - use the helper for both Move (moves.csv) and MoveChange (move_changelog.csv) - add MoveEffectReferenceValidationTestCase covering the helper and the real CSV data Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
…okeAPI#1663) move_changelog.csv is move_id,changed_in_version_group_id,type_id,power,pp,accuracy,priority,target_id,effect_id,effect_chance but the MoveChange builder read effect_id from index 6 (priority) and effect_chance from index 7 (target_id), so MoveChange never received a real effect id and the existing-effect filtering was applied to the wrong column. - extract move_from_csv_row() and move_change_from_csv_row() as module-level builders so the positional parsing used by the real build can be tested - MoveChange now reads effect_id from index 8 and effect_chance from index 9 - rewrite MoveEffectReferenceValidationTestCase to run real CSV rows through the production builders and compare against a header-name-based expectation, plus a synthetic-row check that a missing effect resolves to None and an existing one keeps its id Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
…API#1663) pokemon_v2/test_models.py imports the models at module level and needs a migrated test database, which only manage.py test provided. Add a root conftest.py that selects config.local, calls django.setup() and creates / destroys the test database for the session, so `python -m pytest` collects and runs the same tests as `make test`. Defers to pytest-django when it is present. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
# Conflicts: # data/v2/build.py
The new regression test is a Django TestCase in the existing pokemon_v2/test_models.py and runs under the project's own runner (`uv run manage.py test`, per the Makefile). The root conftest.py was only needed to run a bare `pytest` and is not part of the fix, so it does not belong in this PR.
Contributor
|
@Atakan-24 wasnt this a similar pr #1669 did that not fix this issue |
Author
|
You're right — #1669 fixed the column-index bug and closed the issue. This PR was prepared on Sept 4, before #1669 landed on Sept 8, and I opened it without re-checking first; sorry for the noise. The only thing still missing on master is test coverage for that code path, which #1669 mentioned didn't exist. If that's useful I can strip this PR down to just the regression tests — they locate the |
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.
Fixes #1663
The bug
#1637 replaced the per-row
MoveEffect.objects.get(pk=...)/try/exceptlookupwith a single precomputed set:
That is the right idea, but the line was placed after the
Movebuilder andimmediately before the
MoveChangeblock. So the validity guard only ever reachedMoveChange.move_effect_id.Move.move_effect_idkept assigningint(info[10])unchecked and could therefore point at aMoveEffectrow that wasnever built — a dangling foreign key, which is what #1663 reports.
The fix
existing_effect_idswhere it becomes valid, directly afterbuild_generic((MoveEffect,), "move_effects.csv", ...), so every later buildercan filter against it instead of only the last one.
resolve_existing_id(raw_value, existing_ids)— one place that decideswhat a CSV foreign-key column means: empty column →
None, id that was neverbuilt →
None, otherwise the integer. Both builders call it, so the two cannotdrift apart again.
move_from_csv_row()andmove_change_from_csv_row(). They were inline closures reassigned to the samecsv_record_to_objectsname, which meant no test could reach them. They arenow importable and tested directly.
The column positions differ between the two files and that is exactly the trap:
moves.csvhaseffect_idat index 10,move_changelog.csvat index 8, becauseMoveChangehas nopriorityortargetfield and those two columns are skipped.Tests
Added to the existing
pokemon_v2/test_models.py, so they run under the project'sown runner (
uv run manage.py test, per the Makefile) with no new tooling:resolve_existing_id— built id, unbuilt id, empty column.a synthetic row, locates
effect_id/effect_chanceby header name, and assertsthe builder picked up the same column. This is the class of bug that caused Move effect build order is incorrect #1663,
so it is worth pinning rather than trusting the index.
moves.csvandmove_changelog.csvgoes through theproduction builder, compared against an expectation derived independently by
column name — and the test fails if no row resolves to a built effect, so it
cannot pass by filtering everything to
None.No behaviour change beyond the fix: valid effect references are still assigned,
move_effect_chanceis untouched, and only ids that were never built becomeNone.Disclosure: the change was prepared with an automated pipeline of mine (evaluator →
plan review → implementation → independent review → adversarial review), then
stopped so a human opens, reads and submits it. I have read the diff and the tests
myself and I stand behind them; the CI run on this PR is green on Python 3.10–3.14
plus static checks. Happy to adjust scope or split anything out if you would
rather see it smaller.