fix deepcopy of lazy tree#1922
Merged
Merged
Conversation
Contributor
Author
|
|
Comment on lines
+430
to
+431
| with asdf.open(fn, lazy_tree=True) as af: | ||
| af2 = af.copy() |
Member
There was a problem hiding this comment.
should we also test multiple files open in context managers? To replicate the original issue (or was that using file handles)
Contributor
Author
There was a problem hiding this comment.
Thanks! The original issue can be seen with the following example:
import gc
import roman_datamodels.datamodels as rdm
dst = rdm.ImageModel()
with rdm.open("some_cal.asdf") as src:
dst.meta = src.meta.copy()
del src
gc.collect(2)
dst.meta.ref_file # ok since the copy is shallow
dst.meta.ref_file.crds # fails due to the sub node `crds` not being resolved (made not lazy) during the copyWith this PR that example runs without failure.
What did you have in mind for the multiple files?
I tried to flush out this test with a few "gotchas" (the recursive reference, etc) but it's far from exhaustive. Thanks for the idea!
zacharyburnett
approved these changes
May 20, 2025
Member
zacharyburnett
left a comment
There was a problem hiding this comment.
this LGTM as far as I can tell
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.
Description
This fixes a bug where a deepcopy of a lazy node retains references to the original lazy tree (instead of becoming non-lazy nodes). While adding tests for and fixing this issue I found that
walk_and_modifyconvertsAsdfOrderedDictNodeinstances intodict. That bug is also fixed in this PR and is required for this PR sincewalk_and_modifyis used to handle the deepcopy.Tasks
pre-commiton your machinepyteston your machineno-changelog-entry-needed)changes/:echo "changed something" > changes/<PR#>.<changetype>.rst(see below for change types)docs/pagenews fragment change types...
changes/<PR#>.feature.rst: new featurechanges/<PR#>.bugfix.rst: bug fixchanges/<PR#>.doc.rst: documentation changechanges/<PR#>.removal.rst: deprecation or removal of public APIchanges/<PR#>.general.rst: infrastructure or miscellaneous change