Repository navigation
fix(repository): writes through a loaded instance never reach another item - #61
Merged
Merged
Conversation
… item
update(), delete(), transactions and batch deletes of a loaded instance
used the key its fields render now. After `order.customer_id = "c2"`,
`order.update(...)` updated another customer's order and
`order.delete()` deleted it, while save() and put() refused the changed
key. They now raise the same ValueError before any I/O, and refresh()
reloads the item the instance was loaded from.
Updates of a field that a key template uses (`customer_id` in
`pk="CUSTOMER#{customer_id}"`) were accepted. The item then kept its
key but held another customer_id, so every decode of it rendered
another key, and the instance's later writes went to that item. Such
updates now raise ValueError, like updates of the key itself.
Co-authored-by: Carl Oscar Aaro <[email protected]>
This comment has been minimized.
This comment has been minimized.
…ged key Co-authored-by: Carl Oscar Aaro <[email protected]>
This was referenced Oct 30, 2026
Closed
Closed
Closed
Table updates: provisioned billing without index throughput, and calls while a table is changing
#87
Closed
This was referenced Oct 30, 2026
Closed
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
Two ways of writing through a loaded instance changed an item other than the one it was loaded from.
update(),delete(), transactions (tx.update,tx.delete) and batch deletes of a loaded instance used the key its fields render now, wheresave(),put()and batch puts already raiseValueErrorfor a changed key. Afterorder.customer_id = "c2",order.update(Order.total.set(0))updated customer c2's order with the same order id, andorder.delete()deleted it; a versioned model was no safer when both items had the same version. These now raise the sameValueErrorbefore any I/O.refresh()reloads the item the instance was loaded from, so it undoes such a change instead of loading another item into the instance.update(Customer.customer_id.set("c2"))withpk="CUSTOMER#{customer_id}"was accepted, on instances, by key and in transactions. The item keptpk=CUSTOMER#c1but heldcustomer_id=c2, so every decode of it rendered the key of c2, and the instance's laterdelete()deleted c2's item. Such fields are part of the key, so updates now refuse them with aValueError, as they refuse the key attributes themselves. The guides already described these fields as immutable on loaded instances.Verified with a new integration test on the in-memory backend and MiniStack that covers each of these writes, and with the whole suite, ruff, pyrefly and the consistency checks.
Checklist
AGENT_GUIDE.md, changelog)make checkpasses locally (lint, types, consistency, tests; no Rust change)Worth confirming
refresh()of a loaded instance whose key field changed reloads the item it was loaded from (discarding the change, like any other local change), rather than raising like the writes do.users.update(User.key(...), ...)) refuse fields that a key template uses too, not only updates of instances, since they leave the stored item just as inconsistent.fctl session
Note
Medium risk. It makes
update(),delete(), transactions and batch deletes raiseValueErrorin cases they used to accept, so code that changed a key field of a loaded instance, or updated a field a key template uses, now fails before any I/O. The check sits in the shared_target_keyhelper that every write path goes through.What it does. Writes through a loaded instance used the key its fields render now, so after
order.customer_id = "c2"anupdate()ordelete()hit another customer's order. Those writes now compare the key with the one the instance was loaded with and raise the sameValueErrorassave()andput(), andrefresh()reloads the item the instance came from. Updates of a field that a key template uses are refused too, on instances, by key and in transactions, since they left an item whose key and fields disagreed.Stricter updates.
update()actions on a field that a key template uses (for exampleCustomer.customer_id.set("b")withpk="CUSTOMER#{customer_id}") now raiseValueError, also for updates by key and upserts, where they used to be accepted.fctl review's first look at
b359228· 8 files, +113 −24 · Review agent settings