Fix metadata IDs not persisting when handler is disabled or game not found#3085
Fix metadata IDs not persisting when handler is disabled or game not found#3085
Conversation
…r game not found Co-authored-by: gantoine <[email protected]>
| cleaned_data.update({"launchbox_id": None, "launchbox_metadata": {}}) | ||
|
|
||
| if cleaned_data["ra_id"] and int(cleaned_data["ra_id"]) != rom.ra_id: | ||
| ra_rom = await meta_ra_handler.get_rom_by_id(rom, ra_id=cleaned_data["ra_id"]) |
There was a problem hiding this comment.
@copilot this issue might also be present for the other metadata sources, can you check if that's the case, fix it and update tests?
There was a problem hiding this comment.
Already fixed for all metadata sources in aac4614 — the same if <source>_rom.get("<source>_id"): guard was applied to IGDB, MobyGames, ScreenScraper, RetroAchievements, and Flashpoint, along with a _persists_when_handler_disabled test for each.
…or game not found Co-authored-by: gantoine <[email protected]>
☂️ Python Coverage
Overall Coverage
New FilesNo new covered files... Modified Files
|
Greptile SummaryThis PR fixes a bug where user-supplied metadata source IDs (IGDB, MobyGames, ScreenScraper, RetroAchievements, LaunchBox, Flashpoint) were silently overwritten with Key changes:
The fix is minimal, targeted, and applied consistently across all six sources. Confidence Score: 5/5
Important Files Changed
Sequence DiagramsequenceDiagram
participant Client
participant update_rom as update_rom (rom.py)
participant Handler as Metadata Handler
participant DB
Client->>update_rom: PUT /api/roms/{id} (source_id=X)
update_rom->>update_rom: cleaned_data["source_id"] = X
update_rom->>Handler: get_rom_by_id(X)
alt Handler enabled AND game found
Handler-->>update_rom: SourceRom(source_id=X, metadata=...)
update_rom->>update_rom: source_rom.get("source_id") → truthy
update_rom->>update_rom: cleaned_data.update(source_rom) ✅ full metadata applied
else Handler disabled OR game not found
Handler-->>update_rom: SourceRom(source_id=None)
update_rom->>update_rom: source_rom.get("source_id") → None (falsy)
update_rom->>update_rom: skip update ✅ cleaned_data["source_id"] stays = X
end
update_rom->>DB: save(cleaned_data)
DB-->>update_rom: saved rom
update_rom-->>Client: 200 OK (source_id=X preserved)
Last reviewed commit: 27fb339 |
When a user manually sets a metadata source ID (e.g. LaunchBox, IGDB, MobyGames, ScreenScraper, RetroAchievements, Flashpoint) via "Edit Game", the ID is silently overwritten with
Nonebefore being saved to the DB.Root cause: After calling
get_rom_by_id()for any metadata source, the result is unconditionally merged intocleaned_data. When the handler is disabled or the game isn't found, it returns a Rom object withid=None, clobbering the user-provided value.Fix:
This preserves the user-supplied ID when the handler can't enrich it with metadata, while still applying full metadata updates when the remote lookup succeeds. The fix is applied consistently to all six metadata sources: LaunchBox, IGDB, MobyGames, ScreenScraper, RetroAchievements, and Flashpoint.
Tests: Added
_persists_when_handler_disabledtests for each metadata source to cover theget_rom_by_id → id=Nonepath.Original prompt
🔒 GitHub Advanced Security automatically protects Copilot coding agent pull requests. You can protect all pull requests by enabling Advanced Security for your repositories. Learn more about Advanced Security.