Skip to content
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

Prevent validation of empty tree when AsdfFile is initialized #794

Merged

Conversation

eslavich
Copy link
Contributor

@eslavich eslavich commented May 6, 2020

I noticed this while playing with #792 -- some validation was still occurring despite the new flag. Turns out when AsdfFile is initialized, we're setting the tree property to an empty dict, which results in a validation pass over that object. This PR bypasses that validation by setting _tree directly.

This PR also fixes a minor bug when opening a file containing only blocks, and fixes some tests that relied upon a side-effect of the unnecessary validation pass.

@eslavich eslavich added this to the 2.7.0 milestone May 6, 2020
@codecov
Copy link

codecov bot commented May 6, 2020

Codecov Report

Merging #794 into master will increase coverage by 0.00%.
The diff coverage is 100.00%.

Impacted file tree graph

@@           Coverage Diff           @@
##           master     #794   +/-   ##
=======================================
  Coverage   94.00%   94.00%           
=======================================
  Files          43       43           
  Lines        5054     5056    +2     
=======================================
+ Hits         4751     4753    +2     
  Misses        303      303           
Impacted Files Coverage Δ
asdf/asdf.py 92.88% <100.00%> (+0.02%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update d776a35...7bedc82. Read the comment docs.

@eslavich eslavich force-pushed the eslavich-skip-validating-empty-tree branch from d36cdba to 7bedc82 Compare May 6, 2020 21:38
self.tree = {}
# Bypassing the tree property here, to avoid validating
# an empty tree.
self._tree = AsdfObject()
Copy link
Contributor

@jdavies-st jdavies-st May 18, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might it be better to just pass tree to the setter for self.tree, and have the setter handle None? This whole block seems like it should be handled by the setter, not just on __init__.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When you say whole block, is that the whole if/elif/else? I don't think we want the setter to handle copy-constructing from another AsdfFile, since that requires messing around with blocks and copying other AsdfFile internal variables besides the tree.

I have a slight preference for keeping the commented line as-is, since users can already pass {} to set an empty tree, and it seems tidy for there to be only one way to do it.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That makes sense. 👍

Copy link
Contributor

@jdavies-st jdavies-st left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Other than my comment above, these changes look good.

Copy link
Contributor

@perrygreenfield perrygreenfield left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks OK to me.

@eslavich eslavich merged commit 9447728 into asdf-format:master May 19, 2020
@eslavich eslavich deleted the eslavich-skip-validating-empty-tree branch May 19, 2020 15:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants