Repository navigation
fix(repository): items stored before the model had a version can be saved - #68
Merged
Merged
Conversation
Contributor
Author
|
Stack of 5 open pull requests (from a pass over the library for bugs; #61 to #65 are merged already), merged in this order with "Squash and merge":
The findings that are not fixed here are filed as issues (see the next comment on #72). |
This was referenced Oct 30, 2026
…aved
A loaded instance whose item was stored without a version (written
before the model gained `version()`) has version None. save() treated
it like a new instance and required `attribute_not_exists(pk)`, so it
failed with an unexplained ConditionalCheckFailedError every time, after
refresh() too, and so did tx.save().
save() of such an instance now requires that the item still exists
without a version, and stores version 1. When another writer saved it
first, or deleted it, the call raises VersionConflictError ("stored
version 1, expected no version", "deleted after it was loaded"). The
conflict messages now say "expected version 1".
Co-authored-by: Carl Oscar Aaro <[email protected]>
kalaspuff
force-pushed
the
fixes-stack/07-unversioned-items
branch
from
October 30, 2026 21:40
42b6f82 to
7328e54
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.
What and why
Adding
version: Attr[int] = dynamoxy.version()to a model with stored items made those items impossible to save. An item written before the model had a version loads withversionNone.save()then treated the instance like a new one and sentattribute_not_exists(pk), which always failed because the item exists. The error was an unexplainedConditionalCheckFailedErrorrather thanVersionConflictError,refresh()did not help, andtx.save()failed the same way.update()worked, because it checks a version only when there is one.save()of a loaded instance whose item has no version now requires that the item still exists without a version (attribute_exists(pk) AND attribute_not_exists(version)), and stores version 1. If another writer saved the item first, the call raisesVersionConflictError("stored version 1, expected no version"), and if it was deleted meanwhile, "deleted after it was loaded", without creating it again. A new instance that was never loaded still saves likecreate(). Conflict messages now say "expected version 3" rather than "expected 3".Verified with a new integration test on the in-memory backend and MiniStack (a first save, a stale instance, a deleted item and a transaction), and with the whole suite, ruff, pyrefly and the consistency checks.
Checklist
make checkpasses locally (lint, types, consistency, tests; no Rust change)VersionConflictErrorchanges slightly)fctl session
Note
Medium risk. It changes the condition that
save()sends for loaded instances of versioned models, which every optimistic-locking write goes through, though only for items that have no version.What it does. Fixes
save()for items that were stored before their model got aversion()field. Such an instance loads with versionNone, andsave()used to treat it like a new one and demand that the item did not exist, so it always failed with an unexplainedConditionalCheckFailedError. It now requires that the item still exists without a version and stores version 1, and raisesVersionConflictErrorif another writer saved or deleted the item in the meantime, also inside transactions.Error message wording.
VersionConflictErrormessages now read "expected version 3" instead of "expected 3", and "expected no version" for items that have none, so code or tests that match the old text need updating.fctl review's first look at
7328e54· 5 files, +67 −8 · Review agent settings