feat(bfabric): record entity provenance in dump_yaml / load_yaml - #608
Draft
leoschwarz wants to merge 2 commits into
Draft
feat(bfabric): record entity provenance in dump_yaml / load_yaml#608leoschwarz wants to merge 2 commits into
leoschwarz wants to merge 2 commits into
Conversation
Contributor
📝 "TODO" Changes DetectedSummary: ✅ 1 "TODO" removed ✅ Removed "TODO"s (1)
This comment is automatically updated when "TODO" changes are detected. |
A dumped entity was a bare data dictionary, which lost the instance it came from. Loading it back without passing bfabric_instance produced a half-broken object: both .uri and .refs call EntityUri.from_components(None, ...) and raise. A dump of workunit 1234 on the test instance was also indistinguishable from one on production, since ids are only unique within an instance. Wrap the data in a versioned envelope carrying the entity URI, the dump time and the bfabricPy version. The URI is the only provenance field needed, as it encodes instance, entity type and id, and it is already validated. A model validator cross-checks it against the data's id and classname, so a mismatched or hand-edited file fails at load instead of silently producing a wrong entity. load_yaml now dispatches to the most specific class for the dumped type, and rejects a file holding a different type when called on a subclass. Files written by earlier versions still load, with a DeprecationWarning. The data dictionary stays unvalidated: it is an opaque API payload, and pydantic cannot resolve ApiResponseObjectType anyway (an implicit recursive alias, which hits a RecursionError), so validating it would risk coercing the payload. Closes #351
Collapse the load_yaml class-dispatch ladder, trim the docstrings to the contract the signatures cannot show, and drop a redundant local rebind in parse_document. Bind the parsed YAML document to an object-annotated local so basedpyright does not see an Any argument, and drop the two baseline entries the rewrite made obsolete. No behaviour change.
leoschwarz
force-pushed
the
feature/entity-serialization-metadata
branch
from
August 21, 2026 12:44
11fa791 to
2313568
Compare
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.
Entity.dump_yamlto record the entity's URI, the dump time and the bfabricPy version alongside the data, soEntity.load_yamlrestores a workinguriandrefswithout being told the B-Fabric instance.Entity.load_yamlto return the most specific entity class for the dumped type, and raiseTypeErrorwhen called on a subclass that does not match.dump_yamlto require the entity to have abfabric_instance. Files written by earlier versions still load, with aDeprecationWarning.id/classnamedisagree with its recorded URI, instead of silently producing an entity that points somewhere else.Closes #351
🤖 Prepared with assistance from Claude Opus 5 via Claude Code.