fix: set_status never ran in a transaction (db.IsInTransaction not called) - #65
Merged
sveneberth merged 1 commit intoJul 15, 2026
Conversation
…t called) `if db.IsInTransaction:` tested the function object itself, which is always truthy. So `set_status` always took the "already in transaction" shortcut and executed the transactional function directly -- without opening a transaction and without the retry loop, which was unreachable. All read-check-write cycles built on `set_status` (preconditions, counter increments, status changes) were therefore not atomic and could lose concurrent updates. Call the function: `if db.IsInTransaction():`. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
Fixes a logic bug in set_status where db.IsInTransaction (a function) was previously checked without being called, causing the “already in transaction” branch to always be taken and preventing db.RunInTransaction (and its retry loop) from ever running. The PR also clarifies the transactional behavior in the function’s docstring.
Changes:
- Call
db.IsInTransaction()instead of checking the function object. - Document that the read-check-write cycle executes within a datastore transaction (joining an existing one or opening a new one with retries).
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
sveneberth
enabled auto-merge (squash)
July 15, 2026 20:34
phorward
approved these changes
Jul 15, 2026
phorward
left a comment
Member
There was a problem hiding this comment.
Fortunately, this bug was not in Skeleton.patch() https://github.com/viur-framework/viur-core/blob/main/src/viur/core/skeleton/skeleton.py#L837 anyway, I advise to use skel.patch() now and remove this function entirely.
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.
Problem
set_statusintoolkit/db.pycontains:db.IsInTransactionis a function (viur.core.db.utils.IsInTransaction), so the condition tests the function object itself — which is always truthy. Consequences:set_statusalways takes the "already in transaction" shortcut and executestransaction()directly, without ever opening a transactiondb.RunInTransactionretry loop below is unreachable dead code (theretryparameter has no effect)set_status(precondition checks,+/-counter mutations, status changes) is not atomic — concurrent modifications of the same entity can interleave and lose updatesThis is particularly relevant for consumers like viur-shop, where all order status transitions (
set_ordered/set_paid/set_rts, payment appends) rely onset_statusand can race with concurrent payment-provider callbacks (return handler vs. webhook).Introduced with #25, which added the in-transaction shortcut but missed the call parentheses.
Solution
Call the function:
if db.IsInTransaction():. Also documented the transactional behaviour in theset_statusdocstring.🤖 Generated with Claude Code