Repository navigation
fix(models): documents read from an item keep the keys their class does not declare - #140
Merged
kalaspuff merged 2 commits intoOct 31, 2026
Conversation
…es not declare Writes of loaded instances kept the item's undeclared top-level attributes (ADR 0014), but a document decoded from a map held its declared fields only, so saves by an older version of an application erased keys a newer one added to documents (address.zip_code). A document read from a map now remembers the keys no field declares and writes them back whenever it is encoded; a document the application builds replaces the map (ADR 0020). Refs #99 Co-authored-by: Carl Oscar Aaro <[email protected]>
This comment has been minimized.
This comment has been minimized.
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
Writes of loaded instances keep the item's top-level attributes that no field declares (ADR 0014), but a document decoded from a map held its declared fields only. So a save by an older version of an application, during a rolling deploy, erased keys a newer version had added to a document (
address.zip_code), although the usage guide says older versions "do not erase what a newer one wrote".A document read from a stored map (native documents, models used as documents, and pydantic models) now remembers the map keys no field declares, and writes them back whenever it is encoded:
save()andput()of its item, update values (Mailbox.history.set([...])), lists and maps of documents, and nested documents. A document the application builds replaces the map, so keys of an old address do not leak into a new one. The keys are kept in the instance's__dict__, outside its fields, so==,repr()and pydantic's serialization are unchanged. ADR 0020 records the decision.An integration test on the memory backend and MiniStack stores maps with extra keys the way a newer version would, saves and updates through an older model (native, and a pydantic model with a nested
BaseModel), and checks the stored maps. It failed before the change.uv run pytest, ruff, pyrefly and the consistency checks pass.This completes #99, together with the two pull requests below it in the stack.
Fixes #99
Worth confirming
copy.copy(), oritem.copy()of the model holding it, such as when moving an item to a new key), writes them there too, while the item's undeclared top-level attributes are not copied.fctl session
Note
Medium risk. It changes what is written back to stored items: every document read from an item now carries and rewrites keys its class does not declare, in
save(),put()and update values, for native, model and pydantic documents.What it does. Documents (nested maps) decoded from a stored item now remember the map keys their class does not declare and write them back when encoded, so an older version of an application no longer erases a key such as
address.zip_codethat a newer version added. Documents the application builds still replace the map, and the remembered keys sit in the instance's__dict__, outside==,repr()and pydantic serialization. Copies of a document keep them, as do the documents ofitem.copy(), but not the item's own undeclared top-level attributes. The change comes with ADR 0020, guide and changelog updates and an integration test that runs on both backends.Stored-format behaviour. A loaded document now rewrites unknown keys on every save, and a key can only be removed with an update of its path or by assigning a new document (ADR 0020).
fctl review's first look at
2b7bc44· 7 files, +129 −3 · Review agent settings