Skip to content

fix(repository): updates render derived attributes from the stored item, and require it unchanged - #142

Merged
kalaspuff merged 6 commits into
issues-stack/5-pydantic-valuesfrom
issues-stack/6-derived-updates
Oct 31, 2026
Merged

kalaspuff merged 6 commits into
issues-stack/5-pydantic-valuesfrom
issues-stack/6-derived-updates

Conversation

@fctl-sh

@fctl-sh fctl-sh Bot commented Oct 31, 2026 •

Copy link
Copy Markdown
Contributor

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 rank SCORE#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, rank SCORE#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 a ConditionalCheckFailedError among 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

  • Decision: a concurrent change to the fields a derived attribute is rendered from makes 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 NULL and 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 a ConditionalCheckFailedError. Tests cover the unloaded instance, concurrent writes (versioned and not), the NULL versus 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

fctl-sh Bot and others added 5 commits October 31, 2026 04:53
…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]>
@fctl-review

This comment has been minimized.

Comment thread python/dynamoxy/repository.py Resolved
@fctl-sh

fctl-sh Bot commented Oct 31, 2026

Copy link
Copy Markdown
Contributor Author

Stack of 7 pull requests, merged in this order with "Squash and merge":

  1. fix(memory): PartiQL index reads refuse attributes the index does not hold #137 fix(memory): PartiQL index reads refuse attributes the index does not hold
  2. fix(models): writes through loaded instances use keys stored in another form #138 fix(models): writes through loaded instances use keys stored in another form
  3. fix(models): repositories refuse instances of subclasses and items of other models #139 fix(models): repositories refuse instances of subclasses and items of other models
  4. fix(models): documents read from an item keep the keys their class does not declare #140 fix(models): documents read from an item keep the keys their class does not declare
  5. fix(pydantic): key values and update values run the field's pydantic validators #141 fix(pydantic): key values and update values run the field's pydantic validators
  6. fix(repository): updates render derived attributes from the stored item, and require it unchanged #142 fix(repository): updates render derived attributes from the stored item, and require it unchanged ← this pull request
  7. fix(tables): provisioned billing gives global indexes capacity, and table steps wait for the one before #143 fix(tables): provisioned billing gives global indexes capacity, and table steps wait for the one before

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant