From 294e0bc2981a0d89a7218f2d3db12cf5deef7507 Mon Sep 17 00:00:00 2001 From: Brett Date: Tue, 5 Dec 2023 16:37:59 -0500 Subject: [PATCH] deprecate validation on resolve_references --- asdf/_asdf.py | 14 +++++++++++--- asdf/_tests/test_deprecated.py | 15 +++++++++++++++ docs/asdf/deprecations.rst | 5 +++++ 3 files changed, 31 insertions(+), 3 deletions(-) diff --git a/asdf/_asdf.py b/asdf/_asdf.py index 750db6e74..06030c546 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/asdf/_tests/test_deprecated.py b/asdf/_tests/test_deprecated.py index efea0510f..1d839b0b0 100644 --- a/asdf/_tests/test_deprecated.py +++ b/asdf/_tests/test_deprecated.py @@ -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) diff --git a/docs/asdf/deprecations.rst b/docs/asdf/deprecations.rst index 9de371e90..889488e94 100644 --- a/docs/asdf/deprecations.rst +++ b/docs/asdf/deprecations.rst @@ -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 ===========