-
Notifications
You must be signed in to change notification settings - Fork 58
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
deprecate validation on AsdfFile.tree assignment, AsdfFile.__init__ and AsdfFile.resolve_references #1691
deprecate validation on AsdfFile.tree assignment, AsdfFile.__init__ and AsdfFile.resolve_references #1691
Conversation
asdf/asdf.py
Outdated
except ValidationError: | ||
warnings.warn( | ||
"Validation on tree assignment is deprecated. Please use AsdfFile.validate", AsdfDeprecationWarning | ||
) | ||
raise |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a nice compromise...
asdf/asdf.py
Outdated
@@ -185,7 +185,8 @@ def __init__( | |||
self._tree = tree.tree | |||
self.find_references() | |||
else: | |||
self.tree = tree | |||
self._tree = AsdfObject(tree) | |||
self.validate() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You may have told me this on Friday and I just forgot, but why not also deprecate the validation here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great idea! I added a warning in: b8a80a5
This change triggered some more warnings (turned into errors) in roman_datamodels.
asdf/asdf.py
Outdated
@@ -1215,7 +1222,8 @@ def resolve_references(self, **kwargs): | |||
""" | |||
# Set to the property self.tree so the resulting "complete" | |||
# tree will be validated. | |||
self.tree = reference.resolve_references(self._tree, self) | |||
self._tree = reference.resolve_references(self._tree, self) | |||
self.validate() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I also don't see the value of validating here, but maybe just a failure of imagination.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great idea! I deprecated this (and the unused kwargs
) in: afe8f86
77651c9
to
72cd8d5
Compare
4f83fd3
to
dde00af
Compare
docs/asdf/features.rst
Outdated
(using `AsdfFile.write_to` or `AsdfFile.update`) and when constructing | ||
a new `AsdfFile` object from a tree/dictionary (as in ``AsdfFile(tree)``). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this bit need to change now that we've also removed validation when constructing a new AsdfFile?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes! Thanks for finding this. I removed this mention in 97a09a5
97a09a5
to
690166d
Compare
690166d
to
39b5f09
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚀
39b5f09
to
a7cdd3d
Compare
a7cdd3d
to
7d87d78
Compare
The CI failure for stdatamodels is also seen in stdatamodels main and addressed in: spacetelescope/stdatamodels#260 |
Description
This PR deprecates automatic validation on assignment to
AsdfFile.tree
. This long-undocumented feature (documentation added in asdf 3.0 #1599) can be replaced by a call toAsdfFile.validate
after tree assignment (which is already necessary for tree assignments that don't replace the entire tree).The eventual disabling of the deprecated feature will allow downstream code that currently uses the non-public
_tree
attribute (to avoid the validation on assignment) to be updated to use the publictree
. Here are a few examples:In addition to mentioning this change in the docs and changelog a deprecation warning is added which is triggered only on failed validation during
AsdfFile.tree
assignment. This was done to avoid raising a warning for everyAsdfFile.tree
assignment. As these warnings typically only show during test suite runs it will hopefully signal to any downstream developers that might be relying on the validation onAsdfFile.tree
assignment. A survey ofAsdfFile.tree
assignment in all packages in our downstream testing suggests the deprecation and removal of this feature should only have the positive effect of removing many unnecessary validations (see below for an example).In this example from roman_datamodels.datamodels._core:
While writing out this model to an ASDF file, the model is validated (the
nuke_validation
setting is off by default) first on assignment toasdffile.tree
(due to the feature deprecated in this PR) and validated a second time during the call toasdffile.write_to
.The roman_datamodels downstream failures are due to the new warning (being turned into an error). The failing tests are mostly from the same code used in the example above. The code could be updated (in this case) to avoid the duplicate validation and pass all tests with the changes in this PR:
If this PR is approved a PR can be opened against roman_datamodels with the above change to allow those tests to pass both with and without this asdf PR. After the change is made in roman_datamodels and the downstream test passes here this PR can be merged.
A few tests in roman_datamodels also assume validation on
AsdfFile.__init__
. This branch has updates sufficient to allow all roman_datamodels tests to pass with the source branch for this PR: spacetelescope/roman_datamodels@main...braingram:roman_datamodels:duplicate_validationFixes #315
Checklist: