From de4ea698b8e3bbc29b13c2b0f18055fb2dfb76cb Mon Sep 17 00:00:00 2001 From: izzy lyseggen Date: Mon, 30 Nov 2020 16:59:31 +0000 Subject: [PATCH] feat(serialisation): update detach helper --- .../serialization/base_object_serializer.py | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/speckle/serialization/base_object_serializer.py b/speckle/serialization/base_object_serializer.py index 24015ea..229746e 100644 --- a/speckle/serialization/base_object_serializer.py +++ b/speckle/serialization/base_object_serializer.py @@ -135,22 +135,23 @@ class BaseObjectSerializer: ) return str(obj) - def detach_helper(self, ref_hash: str, obj: Any) -> Dict[str, str]: - """Helper to keep track of detached objects and their depth in the family tree, write fully traversed objects, and create reference objects to place in the parent object + def detach_helper(self, ref_hash: str) -> Dict[str, str]: + """Helper to keep track of detached objects and their depth in the family tree and create reference objects to place in the parent object Arguments: ref_hash {str} -- the hash of the fully traversed object - obj {Any} -- the fully traversed object Returns: dict -- a reference object to be inserted into the given object's parent """ - if ref_hash in self.family_tree[self.leaf] and self.family_tree[self.leaf][ - ref_hash - ] < len(self.detach_lineage): - pass - else: - self.family_tree[self.leaf][ref_hash] = len(self.detach_lineage) + + for parent in self.lineage: + if parent not in self.family_tree: + self.family_tree[parent] = {} + if ref_hash not in self.family_tree[parent] or self.family_tree[parent][ + ref_hash + ] > len(self.detach_lineage): + self.family_tree[parent][ref_hash] = len(self.detach_lineage) return { "referencedId": ref_hash,