-
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
Add flag to skip validation on read #792
Add flag to skip validation on read #792
Conversation
Codecov Report
@@ Coverage Diff @@
## master #792 +/- ##
=======================================
Coverage 93.91% 93.91%
=======================================
Files 43 43
Lines 5043 5044 +1
=======================================
+ Hits 4736 4737 +1
Misses 307 307
Continue to review full report at Codecov.
|
041aca9
to
a4d6a44
Compare
asdf/tests/test_api.py
Outdated
@@ -82,6 +84,27 @@ def test_open_readonly(tmpdir): | |||
pass | |||
|
|||
|
|||
def test_open_validate_on_read(tmpdir): | |||
tmpfile = str(tmpdir.join('invalid.asdf')) |
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 there ever anything written to this file path? I don't see it in the code below, but maybe there is some test magic going on that isn't apparent.
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.
Uhhhhh... waves hand vaguely this is not the tempfile you're looking for
It looks like this |
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.
Looks straightforward and clear to me.
Yup! Well, it'll skip the main validation pass, anyway. The validator will still be used to fill in default values, but that pass doesn't check data types or anything.
AFAIK, if validation and filling defaults are both disabled, the schema isn't used at all. |
Ah, I see. So then only the |
Right, and that matches to the YAML by tag, which is already known in both the file and the subclass, so the schema isn't consulted. |
But tag code is still executed? |
Wow, I didn't realize the schemas were so superfluous. =) |
I made an interesting test: I deleted a bunch of core schemas and opened a file with |
So the only subtlety is regarding defaults. In one case (using schemas), one has the attribute with a default value, but if |
The more I see the implications, the less I like schemas handling defaults. But I may be having a brain short circuit... |
I agree that handling defaults is bad, as it makes data values depend on the vagaries of schemas. Just to save a few bytes. And there's the whole issue of not being able to serialize |
Actually, the defaults are still filled in. That happens on a separate pass through the tree that this PR doesn't impact. My next PR does combine those two passes when both validation and defaults are enabled, but even there the defaults are still filled in with validation disabled. That said, I would love it if we could drop the defaults feature in 3.0. The more time I spend trying to figure out a sane procedure for choosing a default from a complex schema the more I suspect there isn't any such procedure. These schemas just aren't designed to provide a definitive answer to the question "what is the value of an annotation for this node?". IMO the default field should exist only as advice to people writing deserializers, and not be acted upon by asdf code. The type class seems like a more natural place to set defaults. |
This PR adds a flag to
asdf.open
andfits_embed.AsdfInFits.open
that disables validation on read, for situations when the file is already known to be valid and the user wishes to avoid the performance penalty of an unnecessary validation pass.Resolves #565