Skip to content

Commit

Permalink
shallow copy tree before write_to
Browse files Browse the repository at this point in the history
and deep copy key/values that will be modified
  • Loading branch information
braingram committed Apr 24, 2023
1 parent 3e7c0ad commit 6cac202
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions asdf/asdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -1362,12 +1362,14 @@ def write_to(
ignore_unrecognized_tag=self._ignore_unrecognized_tag,
ignore_implicit_conversion=self._ignore_implicit_conversion,
)
naf._tree = self.tree # avoid an extra validate
pre_write_tree = {}
naf._tree = copy.copy(self.tree) # avoid an extra validate

# deep copy keys that will be modified during write
modified_keys = ["history", "asdf_library"]
for k in modified_keys:
if k in self.tree:
pre_write_tree[k] = copy.deepcopy(self.tree[k])
naf._tree[k] = copy.deepcopy(self.tree[k])

# copy over block storage and other settings
block_to_key_mapping = {v: k for k, v in self._blocks._key_to_block_mapping.items()}
# this creates blocks in the new block manager that correspond to blocks
Expand All @@ -1393,10 +1395,6 @@ def write_to(
blk._used = True
blk._data_callback = b._data_callback
naf._write_to(fd, **kwargs)
for k in modified_keys:
if k in self._tree:
del self._tree[k]
self._tree.update(pre_write_tree)

def _write_to(
self,
Expand Down

0 comments on commit 6cac202

Please sign in to comment.