Lock should not be release on ignored exception#3165
Merged
dbernstein merged 1 commit intomainfrom Mar 23, 2026
Merged
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #3165 +/- ##
=======================================
Coverage 93.28% 93.28%
=======================================
Files 493 493
Lines 45711 45713 +2
Branches 6264 6264
=======================================
+ Hits 42641 42645 +4
+ Misses 1983 1982 -1
+ Partials 1087 1086 -1 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
2 tasks
jonathangreen
approved these changes
Mar 23, 2026
6ac1b7f to
290e8fc
Compare
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.
@jonathangreen : I ran into this one while fixing the issues you identified in my overdrive task fix PR.
Description
lock.py: Fixes thelock()context manager so that when an exception inignored_exceptionsis raised, the lock is not released. Previously, ignored exceptions were treated as clean exits (exception_occurred=False), sorelease_on_exit and not exception_occurredevaluated toTrueand the lock was released. The fix addsignored_exception_occurredtracking and skips the release when an ignored exception occurs.test_lock.py: Addstest_lock_not_released_on_ignored_exception, which asserts that the lock remains held when an exception inignored_exceptionsis raised. This test fails before the fix and passes after it.Motivation and Context
The
ignored_exceptionsparameter is intended to keep the lock held when certain exceptions occur (e.g. Celery'sIgnorefromtask.replace()or retry-related exceptions). With the old logic, the lock was still released for those exceptions, which could cause race conditions when retrying or chaining tasks.How Has This Been Tested?
test_lock_not_released_on_ignored_exception, which acquires a lock withignored_exceptions=(ValueError,), raisesValueErrorinside the context manager, and asserts the lock is still held.Checklist