Skip to content

Commit

Permalink
fix __asdf_traverse__ for non-tagged object
Browse files Browse the repository at this point in the history
  • Loading branch information
braingram committed Jan 23, 2024
1 parent 7ae2d7e commit 3fb3d6c
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
3 changes: 2 additions & 1 deletion asdf/_node_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,8 @@ def from_root_node(cls, key, root_identifier, root_node, schema=None, refresh_ex

if cls.traversable(node):
t_node = node.__asdf_traverse__()
info.set_schema_from_node(node, extension_manager)
if hasattr(node, "_tag"):
info.set_schema_from_node(node, extension_manager)

else:
t_node = node
Expand Down
28 changes: 28 additions & 0 deletions asdf/_tests/_regtests/test_1738.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import asdf


def test_info_on_non_tagged_asdf_traverse_object():
"""
Calling info with a tree containing an object that implements
__asdf_traverse__ but does not have a _tag results in an
error
https://github.com/asdf-format/asdf/issues/1738
"""

class MyContainer:
def __init__(self, data):
self.data = data

def __asdf_traverse__(self):
return self.data

c = MyContainer([1, 2, 3])
af = asdf.AsdfFile()
af["c"] = c

# info should not error out
af.info()

# and search should work with the container
assert af.search(type_=int).paths == ["root['c'][0]", "root['c'][1]", "root['c'][2]"]

0 comments on commit 3fb3d6c

Please sign in to comment.