Repository navigation
fix(repository): updates render derived attributes from the stored item, and require it unchanged - #142
Merged
kalaspuff merged 6 commits intoOct 31, 2026
Conversation
…em, and require it unchanged An instance that was not loaded, used as an update target, had its own values taken for the stored ones when an update rendered derived attributes, and updates by key (or of loaded instances without a version) required no condition that the fields they rendered from were unchanged, so a concurrent write left the derived attribute behind. Such updates now read the item, require the fields they took from it unchanged, and update() plans them again from the item as stored now when another writer changed them. Refs #84 Co-authored-by: Carl Oscar Aaro <[email protected]>
This comment has been minimized.
This comment has been minimized.
…ng attribute alike Co-authored-by: Carl Oscar Aaro <[email protected]>
This was referenced Oct 31, 2026
Contributor
Author
|
Stack of 7 pull requests, merged in this order with "Squash and merge":
|
This was referenced Oct 31, 2026
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.
Summary
Updates rendered derived (templated) attributes from the wrong item. An instance that was not loaded, used as an update target, had its own values taken for the stored ones:
players.update(Player(player_id="p1", name="Ada"), Player.score.add(10))with a stored score of 5 stored score 15 but rankSCORE#00000010. Updates by key read the item, and updates of loaded instances without a version used the item they were loaded with, but neither required that item to be unchanged when it wrote. So another writer's change in between left the derived attribute behind (score 26, rankSCORE#00000025), also for versioned models updated by key, where the single-table guide called it exact.Such updates now read the item when the instance was not loaded, and require that the fields the derived attributes are rendered from still have the values they were rendered from. When another writer changed them,
update()plans the update again from the item as stored now (as it already does for unique values). In a transaction, which is not planned again, the operation fails with aConditionalCheckFailedErroramong the cancellation reasons. A loaded versioned instance needs no extra condition, since its version check already guarantees the base.Integration tests on the memory backend and MiniStack cover the unloaded instance, a concurrent write between the read and the update (versioned and not, using middleware that writes after the
GetItem), a loaded instance without a version, and the transaction case. 8 of them failed before the change.uv run pytest, ruff, pyrefly and the consistency checks pass, and the single-table guide and usage guide describe the behaviour.This is the second part of #84. The first part, the version that
put()of an instance that was not loaded writes, needs a decision and is not changed here.Refs #84
Worth confirming
update()read the item again and retry once, rather than raise. That fits what an update means (its actions apply to whatever is stored), but it costs a read and a second request in that case.fctl session
Note
Medium risk. It changes how every
update()of a model with templated (derived) attributes is planned: extra reads, new conditions on the write and one automatic retry, though only for models with derived attributes.What it does. Updates of models with derived (templated) attributes now render those attributes from the item as stored, not from an instance that was never loaded. The write also requires that the stored fields the attributes were rendered from are unchanged; a stored
NULLand a missing attribute count as the same value. When another writer changed them,update()plans the update again from the item as stored now, and in a transaction the operation fails with aConditionalCheckFailedError. Tests cover the unloaded instance, concurrent writes (versioned and not), theNULLversus missing case and the transaction case, and the single-table guide, usage guide and changelog describe the behaviour.Extra read and one retry. Updating an instance that was not loaded now reads the item first when a template needs fields the update does not set, and a concurrent change to those fields costs a second read and request; a second concurrent change in a row still raises
ConditionalCheckFailedError.fctl review's first look at
d002699· 5 files, +177 −11 · Review agent settings