Skip to content

Commit

Permalink
deprecate validation on resolve_references
Browse files Browse the repository at this point in the history
  • Loading branch information
braingram committed Dec 6, 2023
1 parent 85613a5 commit 294e0bc
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 3 deletions.
14 changes: 11 additions & 3 deletions asdf/_asdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -1220,10 +1220,18 @@ def resolve_references(self, **kwargs):
a ASDF file after this operation means it will have no
external references, and will be completely self-contained.
"""
# Set to the property self.tree so the resulting "complete"
# tree will be validated.
if len(kwargs):
warnings.warn("Passing kwargs to resolve_references is deprecated and does nothing", AsdfDeprecationWarning)
self._tree = reference.resolve_references(self._tree, self)
self.validate()
try:
self.validate()
except ValidationError:
warnings.warn(
"Validation during resolve_references is deprecated. "
"Please use AsdfFile.validate after resolve_references to validate the resolved tree",
AsdfDeprecationWarning,
)
raise

def resolve_and_inline(self):
"""
Expand Down
15 changes: 15 additions & 0 deletions asdf/_tests/test_deprecated.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,18 @@ def test_AsdfFile_tree_assignment_validation_deprecation():
ValidationError
):
af.tree = {"history": 42}


def test_AsdfFile_resolve_references_validation_deprecation():
af = asdf.AsdfFile()
af._tree["history"] = 42
with pytest.warns(
AsdfDeprecationWarning, match="Validation during resolve_references is deprecated"
), pytest.raises(ValidationError):
af.resolve_references()


def test_AsdfFile_resolve_references_kwargs_deprecation():
af = asdf.AsdfFile()
with pytest.warns(AsdfDeprecationWarning, match="Passing kwargs to resolve_references is deprecated"):
af.resolve_references(foo=42)
5 changes: 5 additions & 0 deletions docs/asdf/deprecations.rst
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ deprecated and will be disabled in a future version of asdf. Please call
triggering warnings for every tree assignment the warning will only be shown
if the validation triggered by tree assignment fails.

Similarly, validation during ``AsdfFile.resolve_references`` is deprecated (with the
warning only appearing for a failed validation).

Providing ``kwargs`` to ``AsdfFile.resolve_references`` does nothing and is deprecated.

Version 3.0
===========

Expand Down

0 comments on commit 294e0bc

Please sign in to comment.