Skip to content

Better database transaction handling in 'feedback_callback' - #885

Merged
tieneupin merged 5 commits into
mainfrom
feedback-callback-fix
Sep 15, 2026
Merged

tieneupin merged 5 commits into
mainfrom
feedback-callback-fix

Conversation

@tieneupin

Copy link
Copy Markdown
Contributor

Previously, the feedback_callback function made use of a single persistent SQLModel.Session instance that would be passed to every function triggered by the received messages. In the event that a database error is raised (i.e. NoResultFound, MultipleResultsFound, ...) and left uncaught, or the session is not explicitly closed in the except block, the transaction will be left open in the database in an idle_in_transaction state. This will prevent other database operations from running due to locking mechanisms (e.g. our database-wiping CLI murfey.create_db).

This PR fixes that by creating a new SQLModel.Session instance using a context manager for every incoming message. The context manager will close the connection even in the event of an unhandled exception.

@tieneupin
tieneupin marked this pull request as ready for review September 15, 2026 11:01
@tieneupin tieneupin self-assigned this Sep 15, 2026
@tieneupin tieneupin added bug Something isn't working enhancement New feature or request server Relates to the server component and removed enhancement New feature or request labels Sep 15, 2026
@codecov

codecov Bot commented Sep 15, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 11.32075% with 141 lines in your changes missing coverage. Please review.
✅ Project coverage is 55.18%. Comparing base (301bffe) to head (c54d57f).

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #885   +/-   ##
=======================================
  Coverage   55.17%   55.18%           
=======================================
  Files         103      103           
  Lines       11424    11424           
  Branches     1516     1516           
=======================================
+ Hits         6303     6304    +1     
+ Misses       4784     4783    -1     
  Partials      337      337           
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@stephen-riggs stephen-riggs left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Looks fine assuming the main bit is just indented from before. One comment about an old bit of code that can be removed rather than changed

"movie_id": murfey_ids[0],
"program_id": detached_ids[3],
},
_db,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This exists for the old demo setup, and should just be replaced with a log if the transport object isn't set up. Recursively calling feedback_callback seems wrong

@tieneupin tieneupin Sep 15, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thanks for clarifying the bit that's related to the old demo setup. I'll remove it and merge it after.

@tieneupin

Copy link
Copy Markdown
Contributor Author

Looks fine assuming the main bit is just indented from before. One comment about an old bit of code that can be removed rather than changed

Yes, the giant if-elif block has just been indented up until where except occurs. No rewrites beyond pre-commit formatting.

@tieneupin
tieneupin merged commit 87d4bdd into main Sep 15, 2026
14 checks passed
@tieneupin
tieneupin deleted the feedback-callback-fix branch September 15, 2026 16:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working server Relates to the server component

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants