import_data assigns the newest Generation to auto-created packs instead of the set's generation #4

Closed
opened 2026-10-08 21:43:00 +02:00 by freydis · 1 comment
Owner

`apps/tracker/management/commands/import_data.py` (around line 205): when a card references a pack that does not exist yet, the pack is created with

generation = Generation.objects.order_by("-name").first()

i.e. always G4 on current data, even though `pset.generation` is right there and `data/sets.csv` already carries the correct generation per set. On a fresh import every pack of A1..A4b gets G4's pack types and probability tables: 5-slot tables for the 4-card A4b pack, and a 5.2%-weighted "shiny pack" with a slot-6 shiny-only distribution applied to G1 sets that have no shiny cards (which, combined with the dropped-mass behaviour in utils.py, pushes that pack type's chance to 100%).

`update_pack_generations` does not fix this; it only maps legacy v1..v4 names to G1..G4.

Fix: `rarity_version=pset.generation` (and fail/skip loudly if the set has no generation).

\`apps/tracker/management/commands/import_data.py\` (around line 205): when a card references a pack that does not exist yet, the pack is created with generation = Generation.objects.order_by("-name").first() i.e. always G4 on current data, even though \`pset.generation\` is right there and \`data/sets.csv\` already carries the correct generation per set. On a fresh import every pack of A1..A4b gets G4's pack types and probability tables: 5-slot tables for the 4-card A4b pack, and a 5.2%-weighted "shiny pack" with a slot-6 shiny-only distribution applied to G1 sets that have no shiny cards (which, combined with the dropped-mass behaviour in utils.py, pushes that pack type's chance to 100%). \`update_pack_generations\` does not fix this; it only maps legacy v1..v4 names to G1..G4. Fix: \`rarity_version=pset.generation\` (and fail/skip loudly if the set has no generation).
Author
Owner

Confirmed by the repo owner: after every import the generation has to be set by hand. Code-wise, import_sets does read the generation column from data/sets.csv and sets PokemonSet.generation correctly (generations are imported before sets, and the admin "Import Data" button runs the same full command). The part that is never set correctly is Pack.rarity_version, which is what prob_at_least_one_new_card and the pack list actually use: it is always the newest Generation (order_by("-name").first()), regardless of the set. The manual fix in the Pack admin is working around exactly this line. Fix is still rarity_version=pset.generation when creating the pack, plus updating rarity_version on existing packs whose set generation differs.

Confirmed by the repo owner: after every import the generation has to be set by hand. Code-wise, `import_sets` does read the `generation` column from `data/sets.csv` and sets `PokemonSet.generation` correctly (generations are imported before sets, and the admin "Import Data" button runs the same full command). The part that is never set correctly is `Pack.rarity_version`, which is what `prob_at_least_one_new_card` and the pack list actually use: it is always the newest Generation (`order_by("-name").first()`), regardless of the set. The manual fix in the Pack admin is working around exactly this line. Fix is still `rarity_version=pset.generation` when creating the pack, plus updating `rarity_version` on existing packs whose set generation differs.
Sign in to join this conversation.
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
freydis/tcgp-tracker#4
No description provided.