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 Feb 27, 2024
1 parent 698bd30 commit 905f81b
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 2 deletions.
3 changes: 3 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ The ASDF Standard is at v1.6.0
from working. If you want these warnings to produce errors you can
now add your own warning filter [#1757]

- 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
28 changes: 28 additions & 0 deletions asdf/_tests/_regtests/test_1715.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import pytest

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)

main_fn = tmp_path / "main.asdf"

af = asdf.AsdfFile({})
af["id"] = "bogus"
af["myref"] = {"$ref": "external.asdf#/thing"}
af.write_to(main_fn)

with pytest.warns(asdf.exceptions.AsdfDeprecationWarning, match="find_references"):
with asdf.open(main_fn) as af:
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 @@ -111,11 +111,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 905f81b

Please sign in to comment.