-
Notifications
You must be signed in to change notification settings - Fork 7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix get_one_or_create IntegrityError handler (PP-1838) #2134
Conversation
@@ -913,7 +913,7 @@ def get_patron_credential( | |||
:param is_fulfillment: Boolean indicating whether we need a fulfillment credential. | |||
""" | |||
|
|||
def refresh(credential): | |||
def refresh(credential: Credential) -> Credential: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unrelated type hint changes.
allow_persistent_token: bool = False, | ||
allow_empty_token: bool = False, | ||
collection: Collection | None = None, | ||
force_refresh: bool = False, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unrelated type hint changes.
if key in kwargs: | ||
del kwargs[key] | ||
obj = create(db, model, create_method, create_method_kwargs, **kwargs) | ||
return obj |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is the actual fix
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #2134 +/- ##
=======================================
Coverage 90.82% 90.83%
=======================================
Files 352 352
Lines 40854 40854
Branches 8852 8853 +1
=======================================
+ Hits 37104 37108 +4
+ Misses 2442 2438 -4
Partials 1308 1308 ☔ View full report in Codecov by Sentry. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚀
Description
Fix an issue with the Exception handler for an
IntegrityError
in theget_one_or_create
function.If one of the parameters for this function is a sqlalchemy class, then the logging function can cause a
PendingRollbackError
, since the rollback is happening after the log message.Update the function to use db.begin_nested() as a context manager, and write a test for this case.
I added type hints to a couple related functions while I was debugging this before i narrowed in on exactly the cause. These hints are included in this PR. They aren't really related to this fix, but they seem harmless to come in with this one. I can break them out to separate PR if desired.
Motivation and Context
We are seeing a number of
PendingRollbackError
happening via thepatron_activity.sync_patron_activity
celery task. 282 in the last week. Trying to clean up these errors that are causing tasks to fail, so we can add alerts for failed celery tasks.How Has This Been Tested?
Checklist