Fix duplicate fallback cards during catalogue sync - #311
Conversation
|
Nice catch, and a more thorough fix than what we'd done. We hit this exact crash on our fork a while back ( Our fix was narrower: just add a This PR is more elegant because it doesn't just close the timing gap, it also fails safe if the assumption breaks: tracking |
|
@engelben, this was a good catch. The German smp example made it easy to reproduce how native cards and fallback cards could collide when autoflush was disabled. Your flush and rollback changes fixed the original failure. While testing some related edge cases, I added a few more safeguards: • Fallback decisions now count unique native cards instead of the raw API list. I also brought the branch up to date with main and updated the version to 1.27.2. The final result was tested with PostgreSQL 18 and the real TCGdex data. Both consecutive syncs produced the correct 240 native German cards and 8 English fallbacks. All 284 backend tests, 79 frontend tests, and both production builds passed. The PR is ready now. The concrete smp example was especially helpful because it gave us a real dataset to verify the complete fix against. Thank you! |
Fix duplicate fallback cards during catalogue sync
Problem
Database sessions use
autoflush=False.When a localized set contains fewer native cards than its declared total,
_sync_set_card_catalogue()queues the native cards and immediately calculates missing-language fallbacks. Without a flush, that query cannot see the queued native rows and may generate fallback rows with the same primary keys.The German
smpset exposes this consistently. TCGdex reports an official total of 248 cards, while the German card list contains 240 native cards. The remaining 8 cards need English fallback rows.Fix
autoflush=False.main.1.27.2.Expected result
The German
smpsync keeps all 240 native cards, creates only the 8 missing English fallback cards, and completes without duplicate-key or pending-rollback errors. Repeating the sync keeps the same 248 rows.Validation
smpdata.git diff --checkpassed.