fix: correct race condition in with_for_update#607
Merged
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #607 +/- ##
==========================================
+ Coverage 80.32% 80.35% +0.02%
==========================================
Files 87 87
Lines 6405 6433 +28
Branches 828 838 +10
==========================================
+ Hits 5145 5169 +24
Misses 1000 1000
- Partials 260 264 +4 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
|
Documentation preview will be available shortly at https://litestar-org.github.io/advanced-alchemy-docs-preview/607 |
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.



This corrects an issue in the
with_for_updatebehavior:with_for_updateto service.update() or repository.update() only affected the post-flush session.refresh() call. The row that gets copied and mutated was always retrieved with a plain SELECT, so two concurrent writers could both read the same versionwith_for_updateflag is honored when the row is first fetched (both in the service’s item_id branch and inside SQLAlchemyAsyncRepository.get()). When you call service.update(..., with_for_update=True) (or pass the richer dict form/ForUpdateArg), the initial SELECT ... FOR UPDATE runs, so the session holds the expected lock before any field copying or merges occur.