Skip to content

Commit

Permalink
Merge pull request #1095 from WilliamJamieson/bugfix/schema_handle
Browse files Browse the repository at this point in the history
Update to allow for better handling of multiple schema uris per tag uri
  • Loading branch information
eslavich authored Mar 1, 2022
2 parents 5433f97 + 0daf882 commit 02e0a83
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
-------------------

- Bugfix for circular build dependency for asdf. [#1094]
- Fix small bug with handling multiple schema uris per tag. [#1095]

2.10.0 (2022-02-17)
-------------------
Expand Down
15 changes: 15 additions & 0 deletions asdf/extension/_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,21 @@ def handles_type(self, typ):
"""
return typ in self._converters_by_type or get_class_name(typ, instance=False) in self._converters_by_type

def handles_tag_definition(self, tag):
"""
Return `True` if the specified tag has a definition.
Parameters
----------
tag : str
Tag URI.
Returns
-------
bool
"""
return tag in self._tag_defs_by_tag

def get_tag_definition(self, tag):
"""
Get the tag definition for the specified tag.
Expand Down
2 changes: 1 addition & 1 deletion asdf/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ def iter_errors(self, instance, _schema=None):
if _schema is None:
tag = getattr(instance, "_tag", None)
if tag is not None:
if self.serialization_context.extension_manager.handles_tag(tag):
if self.serialization_context.extension_manager.handles_tag_definition(tag):
tag_def = self.serialization_context.extension_manager.get_tag_definition(tag)
schema_uris = tag_def.schema_uris
else:
Expand Down
26 changes: 26 additions & 0 deletions asdf/tests/test_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,3 +133,29 @@ def test_serialize_with_multiple_schemas(tmpdir):
with pytest.raises(asdf.ValidationError):
af["foo_foo"] = FooFoo("bar", 34)
af.write_to(path)


class FooFooConverterlessExtension:
extension_uri = "asdf://somewhere.org/extensions/foo_foo-1.0"
converters = []
tags = [
TagDefinition(
"asdf://somewhere.org/extensions/foo/tags/foo_foo-1.0",
schema_uris=[FOO_SCHEMA_URI, FOOFOO_SCHEMA_URI],
)
]


def test_converterless_serialize_with_multiple_schemas(tmpdir):
with asdf.config_context() as config:
config.add_resource_mapping({FOO_SCHEMA_URI: FOO_SCHEMA, FOOFOO_SCHEMA_URI: FOOFOO_SCHEMA})
config.add_extension(FooFooConverterlessExtension())

path = str(tmpdir / "test.asdf")

af = asdf.AsdfFile()
af["foo_foo"] = "asdf://somewhere.org/extensions/foo/tags/foo_foo-1.0 {bar: bar_bar}"
af.write_to(path)

with asdf.open(path) as af2:
assert af2["foo_foo"] == af["foo_foo"]

0 comments on commit 02e0a83

Please sign in to comment.