Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

info stops schema descent on "traversable" node #1892

Open
braingram opened this issue Dec 24, 2024 · 0 comments
Open

info stops schema descent on "traversable" node #1892

braingram opened this issue Dec 24, 2024 · 0 comments

Comments

@braingram
Copy link
Contributor

braingram commented Dec 24, 2024

Description of the problem

_node_info collection stops descending into a schema if the node is "traversable" (has __asdf_traverse__).

asdf/asdf/_node_info.py

Lines 276 to 277 in a866c98

if parent.schema is not None and not cls.traversable(node):
info.set_schema_for_property(parent, identifier)

even if the parent has a non-None schema. This seems incorrect as a node with __asdf_traverse__ may have a valid subschema.

Example of the problem

import asdf

MY_TAG_URI = "asdf://somewhere.org/tags/foo-1.0.0"
MY_SCHEMA_URI = "asdf://somewhere.org/tags/foo-1.0.0"

schema_bytes = f"""%YAML 1.1
---
$schema: "http://stsci.edu/schemas/yaml-schema/draft-01"
id: {MY_SCHEMA_URI}
title: "some title"
properties:
    foo:
        type: object
        properties:
            bar:
                title: "bar title"
""".encode("ascii")


class MyExtension:
    extension_uri = "asdf://somewhere.org/extensions/foo-1.0.0"
    tags = [asdf.extension.TagDefinition(
        MY_TAG_URI,
        schema_uris=[MY_SCHEMA_URI],
    )]


asdf.get_config().add_resource_mapping({MY_SCHEMA_URI: schema_bytes})


class FooThing:
    def __asdf_traverse__(self):
        return {"bar": 1}

class Thing:
    _tag = MY_TAG_URI

    def __asdf_traverse__(self):
        return {"foo": FooThing()}


ext = MyExtension()

with asdf.config_context() as cfg:
    cfg.add_extension(ext)
    af = asdf.AsdfFile({"t": Thing()})
    af.info()
    print(af.schema_info("title"))

Outputs:

└─t (Thing) # some title
  └─foo (FooThing)
    └─bar (int): 1
{'t': {'title': some title}}

Note that bar has a valid and singular subschema with a title resolvable by _node_info which is not used because FooThing implements __asdf_traverse__. If instead Thing.__asdf_traverse__ returned {"foo": {"bar": 1}} the output includes the title:

root (AsdfObject)
└─t (Thing) # some title
  └─foo (dict)
    └─bar (int): 1 # bar title
{'t': {'foo': {'bar': {'title': bar title}}, 'title': some title}}

System information

asdf version: main
python version: 3.12
operating system: mac

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant