Skip to content

[ROMM-3031] Fix screenshot property on save/state#3037

Merged
gantoine merged 6 commits intomasterfrom
romm-3031
Feb 19, 2026
Merged

[ROMM-3031] Fix screenshot property on save/state#3037
gantoine merged 6 commits intomasterfrom
romm-3031

Conversation

@gantoine
Copy link
Copy Markdown
Member

@gantoine gantoine commented Feb 19, 2026

Description
Explain the changes or enhancements you are proposing with this pull request.

Fixes an issue where screenshots aren't correctly associated with saves/states, especially when uploading via the API.

Fixes #3031

Checklist
Please check all that apply.

  • I've tested the changes locally
  • I've updated relevant comments
  • I've assigned reviewers for this PR
  • I've added unit tests that cover the changes

Screenshots (if applicable)

@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello @gantoine, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request addresses an issue where screenshots were not being correctly associated with Save and State objects. The fix involves refining the Screenshot model's relationships and updating the lookup mechanism for screenshots to ensure they are matched precisely by filename and correctly scoped to the owning user. This prevents incorrect screenshots from being displayed and improves data integrity.

Highlights

  • Screenshot Model Refactoring: The Screenshot model definition was moved to an earlier position in backend/models/assets.py and its relationships (rom and user) were explicitly defined with lazy="joined" and back_populates="screenshots".
  • Improved Screenshot Association Logic: The screenshot property within the Save and State models was updated to use the full file_name instead of file_name_no_ext and now includes user_id when querying for associated screenshots. This ensures more accurate and user-scoped screenshot retrieval.
  • Comprehensive Unit Tests: New unit tests were added to backend/tests/endpoints/test_assets.py to validate the corrected screenshot association logic. These tests cover scenarios for both State and Save objects, ensuring that exact filename matches are preferred and that screenshot retrieval is correctly scoped by user.
Changelog
  • backend/models/assets.py
    • Moved the Screenshot class definition to appear before the Save class.
    • Added explicit rom and user relationships to the Screenshot model.
    • Modified the screenshot property in Save and State classes to use self.file_name instead of self.file_name_no_ext for screenshot lookup.
    • Included user_id=self.user_id in the db_screenshot_handler.get_screenshot call for Save and State objects to ensure user-specific screenshot retrieval.
  • backend/tests/endpoints/test_assets.py
    • Added necessary imports for database handlers and models (Save, Screenshot, State, Platform, Rom, User).
    • Introduced test_get_states_prefers_exact_matching_screenshot_filename to verify that states correctly retrieve screenshots with exact filename matches.
    • Added test_get_states_screenshot_match_is_scoped_by_user to confirm that state screenshots are correctly filtered by the user ID.
    • Implemented test_get_saves_prefers_exact_matching_screenshot_filename to ensure saves also retrieve screenshots based on exact filename matches.
Activity
  • The pull request description is generic and does not contain specific activity details.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Feb 19, 2026

Test Results

804 tests  +3   803 ✅ +3   2m 8s ⏱️ +3s
  1 suites ±0     1 💤 ±0 
  1 files   ±0     0 ❌ ±0 

Results for commit 2706927. ± Comparison against base commit 445bd92.

♻️ This comment has been updated with latest results.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Feb 19, 2026

☂️ Python Coverage

current status: ✅

Overall Coverage

Lines Covered Coverage Threshold Status
13005 8516 65% 0% 🟢

New Files

No new covered files...

Modified Files

File Coverage Status
backend/endpoints/saves.py 76% 🟢
backend/endpoints/screenshots.py 34% 🟢
backend/endpoints/states.py 34% 🟢
backend/handler/database/screenshots_handler.py 88% 🟢
backend/models/assets.py 95% 🟢
TOTAL 65% 🟢

updated for commit: 2706927 by action🐍

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request fixes an issue with how screenshots are associated with saves and states by making the matching logic more specific and scoping it by user. The changes are logical and are supported by new tests. I've added a few suggestions to improve the readability of the new logic and to refactor the new tests for better maintainability by reducing code duplication.

@gantoine
Copy link
Copy Markdown
Member Author

/gemini review

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request refactors the screenshot lookup logic to improve matching for saves and states, and also scopes the lookup by user. The changes are well-tested. A critical bug was identified in screenshots_handler.py regarding incorrect exclusion logic for filenames, which is detailed in the specific code review comment.

@gantoine
Copy link
Copy Markdown
Member Author

/gemini review

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request does a great job of fixing the screenshot matching logic for saves and states by making the queries more specific and user-scoped. The refactoring in screenshots_handler.py and the addition of comprehensive tests are excellent improvements. However, I've found a critical logic error in the filter method's handling of exclude_filenames, which uses or_ where it should be using and_. This will cause mark_missing_screenshots to incorrectly identify screenshots as missing. Please see my detailed comment.

@gantoine gantoine merged commit 520d4c9 into master Feb 19, 2026
9 checks passed
@gantoine gantoine deleted the romm-3031 branch February 19, 2026 16:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] States uploaded via API do not match screenshots and state files.

1 participant