Fix IntegrityError when updating favourites after ROM rescan#3166
Merged
Fix IntegrityError when updating favourites after ROM rescan#3166
Conversation
Copilot
AI
changed the title
[WIP] Fix bug causing failure to update favourites
Fix IntegrityError when updating favourites after ROM rescan
Mar 23, 2026
gantoine
approved these changes
Mar 24, 2026
Contributor
There was a problem hiding this comment.
Pull request overview
Fixes a backend IntegrityError when updating the favourites (collections) after a ROM rescan replaces ROM rows (new DB IDs), leaving collections with stale rom_id references.
Changes:
- Filter
rom_idsto only those that still exist in theromstable before inserting intocollections_roms, preventing foreign key violations. - Skip insert entirely when no valid ROM IDs remain.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Contributor
Test Results (mariadb)998 tests 997 ✅ 2m 37s ⏱️ Results for commit a3ebe16. ♻️ This comment has been updated with latest results. |
Contributor
☂️ Python Coverage
Overall Coverage
New FilesNo new covered files... Modified Files
|
Contributor
Test Results (postgresql)998 tests 997 ✅ 2m 34s ⏱️ Results for commit a3ebe16. ♻️ This comment has been updated with latest results. |
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.
After a rescan that replaces ROMs (new files → new DB IDs), the favourites collection still held stale IDs. Toggling favourites triggered a foreign key violation when attempting to insert
CollectionRomrows referencing non-existentrom_idvalues.Changes
backend/handler/database/collections_handler.py— Inupdate_collection, validaterom_idsagainst theromstable before inserting intocollections_roms. Stale/deleted IDs are silently dropped.Original prompt
This section details on the original issue you should resolve
<issue_title>[Bug] Failed to update favourites</issue_title>
<issue_description>RomM version
Currently 4.7.0, it was installed new at 4.7.0 so there have been no upgrades.
Describe the bug
Clicking add to favourites or remove from favourites pops up with an error "Failed to update favourites".
To Reproduce
Expected behavior
The favourites list to be updated.
Server (please complete the following information):
Client (please complete the following information):
Additional context
It may have been triggered by a rescan replacing a few bad roms with ones with identical names. I did a full scan on the platform after replacing the files.
Container logs reveal this: