Repository navigation
fix(unique)!: upserts that race with creates, unique floats written back, and collections refused - #129
Merged
kalaspuff merged 2 commits intoOct 31, 2026
Conversation
…ck, and collections refused An upsert that set a unique value and found no item added no condition that the item was still missing, so an item created meanwhile lost its value while its guard stayed taken forever. It now requires that, and is planned again from the stored item when it fails because of such a create. Guards compared stored and new values with ==, so a float read back as Decimal deleted and put the same guard item; they now compare stored identities. unique=True on sets, lists and maps (whose guard text has no canonical form) is refused, and collections in unique Any fields raise ValueError before any write. Fixes #82 Co-authored-by: Carl Oscar Aaro <[email protected]>
This comment has been minimized.
This comment has been minimized.
… a create The missing-item condition also covers upserts that read the item to render a derived attribute; test it, and say so in the comment and the changelog. The refusal of unique collections moves to Changed as a breaking change. BREAKING CHANGE: unique=True on set, list, map and document fields is a TypeError when the model is used. Co-authored-by: Carl Oscar Aaro <[email protected]>
This was referenced Oct 31, 2026
fix(models): numbers of union fields render as stored, and literals of plain enum members write
#126
Merged
Contributor
Author
|
Stack of 10 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.
What and why
Three ways unique guards got out of step with their items (#82):
put()already addspartition.not_exists()in this case). When another writer created the item between the read and the write, the upsert overwrote its unique value and never deleted the other writer's guard, which stayed taken forever. The upsert now requires that the item is still missing. When that fails because an item appeared, it reads the item again and writes once more, freeing the replaced value's guard. This is the replan that conditional deletes got in fix(repository): unique models check delete conditions on missing items, and stale deletes and updates read again #110. In a transaction it cancels with aConditionalCheckFailedErrorthat says another writer stored the item and to retry. Upserts of stale loaded instances still raise as before. The same condition covers upserts that read the item to render a derived attribute (Player.score.add(1)withrank="SCORE#{score:08d}"): they wrote a rank rendered from the missing item over the created one (score 6, rankSCORE#00000001), and now render it from the created item._plan_guardscompared the storedDecimal("0.1")with the float0.1using==, so the plan deleted and put the same guard item, which DynamoDB refuses.save(),put()andupdate(Place.latitude.set(0.1))of an instance read back failed with the value unchanged. Guards now compare stored identities, as keys already do.unique=Trueon a set, list, map or document field is now aTypeErrorwhen the model's schema is built, and a collection stored in a uniqueAnyfield raisesValueErrorbefore any write.Verified with integration tests on the in-memory backend and MiniStack, each failing without the fix: a middleware that creates the item right after the upsert's
GetItem(for a unique value, standalone and in a transaction, and for a derived rank), a float field saved, put and updated after a read, and the refused collection fields and values.make checkpasses.Fixes #82
Breaking change
unique=Trueon a set, list, map or document field now raisesTypeErrorwhen the model is used. Such guards never had one text per value, so they did not guarantee uniqueness. Dropunique=Truefrom the field, or keep a canonical string of the value (",".join(sorted(tags))) in a unique field of its own.Checklist
make checkpasses locally (lint, types, clippy, consistency, tests)!in the title and explained aboveWorth confirming
TypeErrorfor declared collection types and aValueErrorfor collection values ofAnyfields; booleans stay allowed.fctl session
Note
Medium risk. It changes how upserts and writes of models with unique fields plan their conditions and guard items, which every such write goes through, and it makes models that declare unique collection fields fail where they were accepted before.
What it does. Fixes three ways unique guard items could get out of step with their items. An upsert that finds no item now requires that the item is still missing, and when another writer created it in the meantime, it reads the item again and writes once more, so the replaced value's guard is freed and derived keys such as
rankare rendered from the created item. Guards of unique floats are compared as stored values, so a float read back no longer deletes and puts the same guard item. Unique set, list and map fields are refused with aTypeErrorwhen the schema is built, and collection values in uniqueAnyfields raise aValueErrorbefore any write.Breaking change. Models that declare
unique=Trueon a set, list, map or document field now raise aTypeErroras soon as their schema is used, so applications with such models stop working until they remove the option or keep a canonical string in a unique field of its own.fctl review's first look at
3ba79de· 8 files, +185 −12 · Review agent settings