diff --git a/asdf/_tests/test_deprecated.py b/asdf/_tests/test_deprecated.py index 93689ce62..07016533c 100644 --- a/asdf/_tests/test_deprecated.py +++ b/asdf/_tests/test_deprecated.py @@ -24,3 +24,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) diff --git a/asdf/asdf.py b/asdf/asdf.py index b0a7f2fd4..bf190e4f9 100644 --- a/asdf/asdf.py +++ b/asdf/asdf.py @@ -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): """ diff --git a/docs/asdf/deprecations.rst b/docs/asdf/deprecations.rst index dc4c7cc1d..52788aacc 100644 --- a/docs/asdf/deprecations.rst +++ b/docs/asdf/deprecations.rst @@ -15,6 +15,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 ===========