asdf-format/asdf

Objects that implement `__asdf_traverse__` are expected to have a `_tag`

braingram opened this issue · 0 comments

Description of the problem

Adding __asdf_traverse__ to an object will cause info (and possibly other commands) to fail if the object does not also contain a _tag attribute.

Example of the problem

import asdf

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
af.info()

The above example produces the following error:

Traceback (most recent call last):
  File "/Users/bgraham/projects/src/asdf/traverse_error.py", line 15, in <module>
    af.info()
  File "/Users/bgraham/projects/src/asdf/asdf/_asdf.py", line 1426, in info
    lines = display.render_tree(
  File "/Users/bgraham/projects/src/asdf/asdf/_display.py", line 45, in render_tree
    info = create_tree(
  File "/Users/bgraham/projects/src/asdf/asdf/_node_info.py", line 44, in create_tree
    schema_info = NodeSchemaInfo.from_root_node(
  File "/Users/bgraham/projects/src/asdf/asdf/_node_info.py", line 285, in from_root_node
    info.set_schema_from_node(node, extension_manager)
  File "/Users/bgraham/projects/src/asdf/asdf/_node_info.py", line 242, in set_schema_from_node
    tag_def = extension_manager.get_tag_definition(node._tag)
AttributeError: 'MyContainer' object has no attribute '_tag'

System information

asdf version: main
python version: 3.10
operating system: mac osx