Skip to content

Commit

Permalink
fix bug where a dict with an id causes contained refs to fail to resolve
Browse files Browse the repository at this point in the history
  • Loading branch information
braingram committed Dec 21, 2023
1 parent 45b1661 commit f7dc3f4
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 2 deletions.
3 changes: 3 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ The ASDF Standard is at v1.6.0
is removed in an upcoming asdf release will be ``False`` and
asdf will no longer by-default memory map arrays. [#1667]

- Fix bug where a dictionary containing a key ``id`` caused
any contained references to fail to resolve [#1716]

3.0.1 (2023-10-30)
------------------

Expand Down
22 changes: 22 additions & 0 deletions asdf/_tests/_regtests/test_1715.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import asdf


def test_id_in_tree_breaks_ref(tmp_path):
"""
a dict containing id will break contained References
https://github.com/asdf-format/asdf/issues/1715
"""
external_fn = tmp_path / "external.asdf"

external_tree = {"thing": 42}

asdf.AsdfFile(external_tree).write_to(external_fn)

uri = asdf.util.filepath_to_url(str(tmp_path / "main.asdf"))
af = asdf.AsdfFile({}, uri=uri)
af["id"] = "bogus"
af["myref"] = {"$ref": "external.asdf#/thing"}
af.find_references()
af.resolve_references()
assert af["myref"] == 42
4 changes: 2 additions & 2 deletions asdf/reference.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,11 +112,11 @@ def find_references(tree, ctx, _warning_msg=False):
`Reference` objects.
"""

def do_find(tree, json_id):
def do_find(tree):
if isinstance(tree, dict) and "$ref" in tree:
if _warning_msg:
warnings.warn(_warning_msg, AsdfDeprecationWarning)
return Reference(tree["$ref"], json_id, asdffile=ctx)
return Reference(tree["$ref"], asdffile=ctx)
return tree

return treeutil.walk_and_modify(tree, do_find, ignore_implicit_conversion=ctx._ignore_implicit_conversion)
Expand Down

0 comments on commit f7dc3f4

Please sign in to comment.