The serializer_id attribute
#167
Locked
damskii9992
announced in
ADRs
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Context
When serializing objects which reference other objects, such as with dependencies in #121, it is necessary to be able to save this reference across sessions.
The
unique_nameidentification system provides unique id's for objects, but due to them being simple, user-customizable, and auto-generated with a simple increasing integer, they fail to be unique across multiple sessions which results in clashes or inconsistencies upon de-serialization.The serialization-only id
To solve this issue we have implemented a transient ID meant only for serialization/de-serialization.
The
serializer_idproperty is name-mangled (i.e. it is called__serializer_id) to avoid accidental overwrites, and it is only created and assigned to an object when it gets references by another object (such as by being used in a dependentParameter).Upon serialization of objects, the
serializer_idis added to the serialized objects dictionary and any references to the object, including references byunique_names, are replaced with thisserializer_idto ensure reliable reconstruction of this reference upon de-serialization.When de-serializing objects, the references are initially ignored since objects can be de-serialized in any order and it is crucial for the referenced object to exist before attempting to re-create the reference.
Once all objects have been de-serialized (they now hold their
serializer_idattribute if it existed in their serialized dictionary), all the references can be re-created by running the corresponding reference resolver (dependency_resolverfor dependentParameters).This reference resolver will go through an object, look up its references by their
serializer_idby going through all the objects in theglobal_objectsmap, replace this reference with a regular object reference orunique_namereference, and then delete theserializer_idon those objects, hence why theserializer_idis called "transient".Potential issues or pitfalls
The reference resolver can only be run once. Since it deletes
serializer_idsafter using them, any subsequent objects with references with theseserializer_ids, de-serialized after the reference resolver has been run, won't be able to re-create their references since thisserializer_idno longer exists. To avoid this pitfall, the reference resolver should only be run after all object have been de-serialized.Link to the ADR suggestion:
#164
Beta Was this translation helpful? Give feedback.
All reactions