mirror of
https://github.com/rommapp/romm.git
synced 2026-06-28 06:46:00 +00:00
PR #3425 dropped `lazy="joined"` from `RomFile.rom` and removed the `joinedload(RomFile.rom)` from the ROM loaders to speed up the gallery query. That left the `RomFile.rom` backref unpopulated. Single-file downloads only read `RomFile.full_path` (built from `file_path`/ `file_name`), so they kept working, but multi-file (game folder) downloads call `file_name_for_download()` / `is_top_level`, which read `self.rom.full_path`. With no eager-loaded backref, that triggered a lazy load on a detached instance once the handler session closed, raising `DetachedInstanceError` and returning a 500. Rather than reverting the loader changes (and the gallery gains), wire the `RomFile.rom` backref up in Python from the parent ROM we already hold in memory, via `set_committed_value`. This is zero extra DB cost and only runs on the detail/download paths (`with_details` and `get_roms_by_fs_name`); the optimized `filter_roms` gallery query is untouched. https://claude.ai/code/session_01PSXKmejPRzdxLFMN6P2QQ4