Repository navigation
fix(models): writes through loaded instances use keys stored in another form - #138
Merged
kalaspuff merged 3 commits intoOct 31, 2026
Conversation
…er form A key that another writer stored in a form that decodes to the same values but that dynamoxy does not write (an upper-case UUID, a date as 20260102, also inside a key template) rendered canonically from the loaded instance, which addresses no item: save(), delete() and update() raised "the key of this instance changed", and primary_key() returned the key of no item. Writes through a loaded instance and primary_key() now use the key as stored, as ADR 0015 says. Refs #99 Co-authored-by: Carl Oscar Aaro <[email protected]>
Co-authored-by: Carl Oscar Aaro <[email protected]>
This comment has been minimized.
This comment has been minimized.
…ored Co-authored-by: Carl Oscar Aaro <[email protected]>
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
A key that another writer stored in a form that decodes to the same values, but that dynamoxy does not write (an upper-case UUID, a date as
20260102, also inside a key template such asDEVICE#{device_id}), made its loaded instances address no item: they render the canonical form, sosave(),delete()andupdate()through them raised "the key of this instance changed", andprimary_key()returned the key of no item. ADR 0015 says keys of loaded instances are the stored keys.Writes through a loaded instance (puts, saves, updates, deletes, batches and transactions) and its
primary_key()now use the key as stored when the instance's key fields still decode to the same values; a key field that really changed is refused as before. Immutable fields had the same problem (save()raised "is immutable" for a value stored that way) and keep their stored form too. The checks decode stored values only when the rendered form differs from the stored one, so ordinary writes cost nothing more.An integration test, on the memory backend and MiniStack, stores such a key the way another writer would and saves, refreshes, updates (directly and in a transaction), batch-puts and deletes through the loaded instance, with an immutable date stored the same way; it failed before the fix.
uv run pytest, ruff and pyrefly pass. The modeling guide says how such keys behave.Refs #99
Worth confirming
save(), since ADR 0015 documents rewriting a value's format on save as a migration path.fctl session
Note
Medium risk. It changes which key every write through a loaded model instance (save, update, delete, batches, transactions) sends to DynamoDB, though only when the stored key differs in form from the rendered one.
What it does. When another writer stored a key in a form dynamoxy reads but does not write (an upper-case UUID, a date as
20260102), loaded instances rendered the canonical key, which addresses no item, sosave(),update()anddelete()failed with "the key of this instance changed". Writes through a loaded instance andprimary_key()now use the key as stored when the key fields still decode to the same values, immutable fields keep their stored form on save, and after a write the derived key fields of the instance hold the stored key. A new integration test stores such a key and writes through the loaded instance in every way.Stored forms kept on write. Only key attributes and immutable fields keep their stored form on
save(); other attributes, index keys included, are rewritten in the canonical form.fctl review's first look at
f7634dc· 8 files, +152 −20 · Review agent settings