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 search and schema_info do not use the AsdfFile.extension_manager #1882

Open
braingram opened this issue Dec 19, 2024 · 0 comments · May be fixed by #1884
Open

info search and schema_info do not use the AsdfFile.extension_manager #1882

braingram opened this issue Dec 19, 2024 · 0 comments · May be fixed by #1884

Comments

@braingram
Copy link
Contributor

Description of the problem

info (and search and schema_info) do not use the extension manager of the AsdfFile instance from which they're called. This can lead to a number of issues including:

  • ignoring extensions passed to AsdfFile.__init__ (seen below)
  • ignoring the standard version of AsdfFile (can be seen with small modifications to the below example)

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"
""".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 Thing:
    _tag = MY_TAG_URI

    def __asdf_traverse__(self):
        return []


ext = MyExtension()

print("=== Extension not registered ===")
# if we don't register the extension
af = asdf.AsdfFile({"t": Thing()})
# we don't see the title
af.info()

print("=== Extension registered with config ===")
with asdf.config_context() as cfg:
    # if we register the extension with config
    cfg.add_extension(ext)
    af = asdf.AsdfFile({"t": Thing()})
    # we see the title
    af.info()

# if we pass the extension to __init__...
print("=== Extension passed to __init__ ===")
af = asdf.AsdfFile({"t": Thing()}, extensions=[ext])
# we don't see the title
af.info()

Output:

=== Extension not registered ===
root (AsdfObject)
└─t (Thing): <__main__.Thing object at 0x103535030>
=== Extension registered with config ===
root (AsdfObject)
└─t (Thing): <__main__.Thing object at 0x10486a440> # some title
=== Extension passed to __init__ ===
root (AsdfObject)
└─t (Thing): <__main__.Thing object at 0x104b9d8d0>

System information

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

braingram added a commit to braingram/asdf that referenced this issue Dec 20, 2024
@braingram braingram linked a pull request Dec 20, 2024 that will close this issue
6 tasks
braingram added a commit to braingram/asdf that referenced this issue Dec 20, 2024
braingram added a commit to braingram/asdf that referenced this issue Dec 24, 2024
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

Successfully merging a pull request may close this issue.

1 participant