-
Notifications
You must be signed in to change notification settings - Fork 21
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
Remove duplicate validation, replace assumed validation on AsdfFile.__init__
with AsdfFile.validate
#301
Remove duplicate validation, replace assumed validation on AsdfFile.__init__
with AsdfFile.validate
#301
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #301 +/- ##
==========================================
+ Coverage 97.44% 97.50% +0.06%
==========================================
Files 28 29 +1
Lines 2698 2726 +28
==========================================
+ Hits 2629 2658 +29
+ Misses 69 68 -1 ☔ View full report in Codecov by Sentry. |
af = asdf.AsdfFile() | ||
af["roman"] = self._instance | ||
af.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.
This seems a bit verbose. Is there something wrong with:
self._asdf = asdf.AsdfFile({"roman": self._instance})
self._asdf.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.
Thanks for taking a look and good question. Unfortunately, the code you proposed would validate the instance twice. Once during AsdfFile.__init__
and again during AsdfFile.validate
. Also, the reason for this PR is that asdf is deprecating validation during AsdfFile.__init__
. The code you proposed would result in a DeprecationWarning
and test failure when the validation fails. The code proposed in this PR avoids the possibility of the DeprecationWarning
by not providing the _instance
during AsdfFile.__init__.
.
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.
Is asdf deprecating passing a dictionary directly to the AsdfFile
initializer? If so, then that is a huge change of behavior!
If it's simply raising DepreciationWarning
because of the validation change then a more thoughtful change should be considered as initializing with a dictionary is an extremely common usage of AsdfFile
.
I would request that a validate=True
option should be added to the initializer which preserves the current behavior without deprecation. You can set it so it defaults to None
and raises the warning of impending behavior changes in that case.
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.
asdf is not deprecating initializing with a dictionary. However if that dictionary is invalid one will see a DeprecationWarning
noting that validation on AsdfFile.__init__
is deprecated and a ValidationError
. If the dictionary is valid no warning or error will be seen. This was done to allow test suites (like the one in roman_datamodels
) to detect the change.
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.
@WilliamJamieson I'm not sure I addressed your comments here. asdf is deprecating (for removal) validation on AsdfFile.__init__
to reduce the duplication of functionality in asdf. Adding a validate
keyword that triggers validation overlaps with functionality that is already provided by AsdfFile.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.
@WilliamJamieson does this PR look good to you? I'd like to resolve this so I can merge the PR in asdf adding the deprecation warning without breaking the CI here.
68355d0
to
5d9a8fc
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.
LGTM modulo William's comments.
5d9a8fc
to
8ca2580
Compare
e79c44a
to
d99ddf7
Compare
d99ddf7
to
8bfd39a
Compare
This PR removes duplicate validation during
to_asdf
:roman_datamodels/src/roman_datamodels/datamodels/_core.py
Lines 219 to 223 in 70f05e8
The assignment to
tree
triggers the first validation and thewrite_to
triggers a second.This PR also updates several uses of
AsdfFile.__init__
to validate tree contents (replacing it with an explicit call toAsdfFile.validate
).These changes are to prepare roman_datamodels for an upcoming deprecation in asdf (see asdf-format/asdf#1691).
Regression tests running with no errors: https://plwishmaster.stsci.edu:8081/job/RT/job/Roman-Developers-Pull-Requests/515/
Checklist
CHANGES.rst
under the corresponding subsection