Better database transaction handling in 'feedback_callback' - #885
Conversation
…every received message in 'feedback_callback'
Codecov Report❌ Patch coverage is 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:
|
stephen-riggs
left a comment
There was a problem hiding this comment.
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, |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Thanks for clarifying the bit that's related to the old demo setup. I'll remove it and merge it after.
Yes, the giant |
Previously, the
feedback_callbackfunction made use of a single persistentSQLModel.Sessioninstance 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 theexceptblock, the transaction will be left open in the database in anidle_in_transactionstate. This will prevent other database operations from running due to locking mechanisms (e.g. our database-wiping CLImurfey.create_db).This PR fixes that by creating a new
SQLModel.Sessioninstance using a context manager for every incoming message. The context manager will close the connection even in the event of an unhandled exception.