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

Fix some validator-specific crashes #395

Merged
merged 11 commits into from Jul 17, 2020
Merged

Conversation

ml-evs
Copy link
Member

@ml-evs ml-evs commented Jul 10, 2020

This PR aims to fix some crashes of the validator, caused either by validator-specific code (cf50cf3) or by crashes internal to the pydantic validator (2b4c3bd). It also adds a few niceties to the validator, including the separation of "internal errors" from expected validation errors, as listed below. Importantly, this PR does not update any of the models that are currently causing validation errors, these should be addressed in another PR.

The commits can all be reviewed separately, 8e92308 dominates the diff but is mostly just piping code without any "business logic".

Changes:

  • cf50cf3 Fixed another occurrence of an optional field without a default value (my fault). I can't spot any more in the codebase (using the slightly convoluted grep below) (closes Validator treats top-level 'included' array as mandatory #393):
    $ grep "Optional.*Field(" -r . -A 1 -h | grep -v "\-\-" | grep -v Field | grep -v None | grep -v default | grep -v "ok"
  • 2b4c3bd Fixed issue where passing a dict to pydantic when it was expecting a list was causing a crash with a huge traceback (closes Validation of 'structures' type crashes #397)
  • 442a407 Improved help string for --verbosity (closes Validator verbosity levels need more detailed description #396).
  • 8e92308 Added internal error handling to prevent all future crashes. These get reported separately to validation errors.
  • 3a917aa Added a couple of self-explanatory quality of life flags, --fail_fast and --skip_optional.
  • ced32ba Allow for links objects to be passed to validation in pagination test (rather than just strings) and enforce a maximum pagination recursion depth when validating responses (5)
  • 84ab0b1 Pending improvements to the queries we try as validation, I've reduced the set of queries tested from the spec examples to only those that appear mandatory. What remains is still very useful for validating the responses format.
  • Several changes to validator CLI flags, and renamed script as optimade-validator.

@ml-evs ml-evs added priority/high Issue or PR with a consensus of high priority validator Related to the OPTIMADE validator labels Jul 10, 2020
@ml-evs
Copy link
Member Author

ml-evs commented Jul 10, 2020

Once the checks pass, I'll shamelessly wield some executive power and merge this so that we can close #393 and @merkys can get on with his work!

merkys
merkys previously approved these changes Jul 10, 2020
Copy link
Member

@merkys merkys left a comment

Choose a reason for hiding this comment

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

I confirm I no longer experience #393 on this branch. Many thanks!

@ml-evs
Copy link
Member Author

ml-evs commented Jul 10, 2020

I confirm I no longer experience #393 on this branch. Many thanks!

Great, if you're happy staying on this branch, I'll bunch any other fixes together in this PR.

We're getting a weird build failure for Python 3.7 (I saw it in @CasperWA's pytest PR too) so its perhaps not advisable to merge and release just yet.

@merkys
Copy link
Member

merkys commented Jul 10, 2020

Great, if you're happy staying on this branch, I'll bunch any other fixes together in this PR.

Sure. I am as well comfortable with switching between branches.

We're getting a weird build failure for Python 3.7 (I saw it in @CasperWA's pytest PR too) so its perhaps not advisable to merge and release just yet.

Take your time!

@CasperWA
Copy link
Member

We're getting a weird build failure for Python 3.7 (I saw it in @CasperWA's pytest PR too) so its perhaps not advisable to merge and release just yet.

Yeah, this is due to GitHub Actions update of the minor 3.7 version they use. We're seeing the same issues for AiiDA. I am unclear how to solve this.

@ml-evs
Copy link
Member Author

ml-evs commented Jul 10, 2020

Yeah, this is due to GitHub Actions update of the minor 3.7 version they use. We're seeing the same issues for AiiDA. I am unclear how to solve this.

Ugh, tried pinning to 3.7.7 inside actions and it won't let you. Pretty bad of GH to force you to switch to 3.7.8 (released 8 days ago...), presumably some package (seems to be PyYAML?) is pinned to 3.7.7 or below so it is failing to install. 3.7.8 isn't even out on conda yet!

@ml-evs
Copy link
Member Author

ml-evs commented Jul 10, 2020

Just found the relevant issues (raised by AiiDA peeps!) here, actions/setup-python#107

If move to the setup-python@v2 action we can pin the version to 3.7.7 for now until PyYAML is happy again.

@CasperWA
Copy link
Member

Yeah, this is due to GitHub Actions update of the minor 3.7 version they use. We're seeing the same issues for AiiDA. I am unclear how to solve this.

Ugh, tried pinning to 3.7.7 inside actions and it won't let you. Pretty bad of GH to force you to switch to 3.7.8 (released 8 days ago...), presumably some package (seems to be PyYAML?) is pinned to 3.7.7 or below so it is failing to install. 3.7.8 isn't even out on conda yet!

I believe we can work around it temporarily by not testing adapters (i.e., AiiDA and more) for v3.7 for now perhaps?
This would mean simply adding some if logic to a couple of steps, having it check the python version.

@CasperWA
Copy link
Member

Just found the relevant issues (raised by AiiDA peeps!) here, actions/setup-python#107

If move to the setup-python@v2 action we can pin the version to 3.7.7 for now until PyYAML is happy again.

Ah cheers :) I was too lazy to find it myself 😅 Even though I'm technically part of the AiiDA developers team ;)

@ml-evs
Copy link
Member Author

ml-evs commented Jul 10, 2020

For separation of concerns, I'm fixing the CI in #400 instead of here.

I've done a lot of robustifying of the validator which I will push here shortly.

@ml-evs ml-evs force-pushed the ml-evs/hotfix_validator_models branch from 95f5811 to f33ef2e Compare July 10, 2020 15:10
@codecov
Copy link

codecov bot commented Jul 10, 2020

Codecov Report

Merging #395 into master will decrease coverage by 0.13%.
The diff coverage is 64.56%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #395      +/-   ##
==========================================
- Coverage   91.09%   90.95%   -0.14%     
==========================================
  Files          55       55              
  Lines        2459     2522      +63     
==========================================
+ Hits         2240     2294      +54     
- Misses        219      228       +9     
Flag Coverage Δ
#unittests 90.95% <64.56%> (-0.14%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
optimade/validator/__init__.py 9.37% <0.00%> (-0.63%) ⬇️
optimade/validator/validator.py 77.10% <65.00%> (+2.62%) ⬆️
optimade/models/entries.py 97.43% <66.66%> (-2.57%) ⬇️
optimade/validator/validator_model_patches.py 100.00% <100.00%> (ø)

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 b310909...001a642. Read the comment docs.

@ml-evs ml-evs force-pushed the ml-evs/hotfix_validator_models branch 3 times, most recently from 87d3c63 to 442a407 Compare July 10, 2020 15:35
@ml-evs ml-evs changed the title Fix "included" in patched validator models Fix some validator-specific crashes Jul 10, 2020
@ml-evs ml-evs force-pushed the ml-evs/hotfix_validator_models branch 2 times, most recently from 1f90287 to 84ab0b1 Compare July 10, 2020 17:07
@ml-evs
Copy link
Member Author

ml-evs commented Jul 10, 2020

Hi @merkys, this PR should now fix many of the crashes/false positives you were running into on your test server. Those that remain (mostly caused by #399) will require changes to our models and must be fixed elsewhere.

If you're able to test the validator on this branch again and report any further issues before we review it, that would be great!

@ml-evs ml-evs requested review from CasperWA and merkys July 10, 2020 17:15
Copy link
Member

@CasperWA CasperWA left a comment

Choose a reason for hiding this comment

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

Great work here @ml-evs !

I have a few suggested changes :)

optimade/models/entries.py Show resolved Hide resolved
optimade/validator/__init__.py Show resolved Hide resolved
optimade/validator/__init__.py Outdated Show resolved Hide resolved
optimade/validator/__init__.py Outdated Show resolved Hide resolved
optimade/validator/__init__.py Outdated Show resolved Hide resolved
optimade/validator/validator.py Outdated Show resolved Hide resolved
optimade/validator/validator.py Outdated Show resolved Hide resolved
optimade/validator/validator.py Outdated Show resolved Hide resolved
optimade/validator/validator.py Outdated Show resolved Hide resolved
optimade/validator/validator.py Outdated Show resolved Hide resolved
These errors should be handled differently to ValidationError and
ResponseError as they indicate a problem with the validator itself.
- Allow links objects to be passed in pagination
- Enforced maximum recursion depth (5) for pagination tests
@ml-evs ml-evs force-pushed the ml-evs/hotfix_validator_models branch 4 times, most recently from 0cde9df to 04ac0ad Compare July 16, 2020 22:12
Co-authored-by: Casper Welzel Andersen <CasperWA@users.noreply.github.com>
@ml-evs ml-evs force-pushed the ml-evs/hotfix_validator_models branch from 04ac0ad to 56708a1 Compare July 16, 2020 22:13
@ml-evs
Copy link
Member Author

ml-evs commented Jul 16, 2020

We have another validator-action chicken/egg problem, as it needs to be updated with the new way of handling --verbosity (good suggestion @CasperWA :P) and the other now-hyphenated flags.

@ml-evs
Copy link
Member Author

ml-evs commented Jul 16, 2020

We have another validator-action chicken/egg problem, as it needs to be updated with the new way of handling --verbosity (good suggestion @CasperWA :P) and the other now-hyphenated flags.

Making the PR for this too

@CasperWA
Copy link
Member

We have another validator-action chicken/egg problem, as it needs to be updated with the new way of handling --verbosity (good suggestion @CasperWA :P) and the other now-hyphenated flags.

The error message from the validator (in this repo) might also be a bit better, see this line.
Copied here as well for posterity:

optimade_validator: error: unrecognized arguments: http://gh_actions_host:3213/v1

Copy link
Member

@CasperWA CasperWA left a comment

Choose a reason for hiding this comment

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

Some very minor changes.
I think the switching of big and small in __init__.py makes sense, the other suggested changes I leave completely up to you.

But other than that, since this repository holds the source for the validator action, this PR must be merged before the validator action PR can be merged.
And as long as this test succeeds (as here), i.e., the test that has been updated to point to the latest commit of this PR (should be updated int the validator action accordingly), I see that as a "check"/success for the docker-image CI check here.

optimade/validator/__init__.py Outdated Show resolved Hide resolved
optimade/validator/__init__.py Outdated Show resolved Hide resolved
optimade/validator/validator.py Show resolved Hide resolved
optimade/validator/validator.py Show resolved Hide resolved
Use -t for --as-type (instead of -a).

Co-authored-by: Andrius Merkys <andrius.merkys@gmail.com>
@ml-evs ml-evs requested a review from CasperWA July 17, 2020 09:57
Copy link
Member

@CasperWA CasperWA left a comment

Choose a reason for hiding this comment

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

Thanks for this @ml-evs !

For posterity: @ml-evs didn't like my suggestion to remove the > 0 in the latest review, due to it being more clear in its explicit form.

@ml-evs ml-evs merged commit 93e50b1 into master Jul 17, 2020
@ml-evs ml-evs deleted the ml-evs/hotfix_validator_models branch July 17, 2020 10:06
@merkys
Copy link
Member

merkys commented Jul 22, 2020

Hi @merkys, this PR should now fix many of the crashes/false positives you were running into on your test server. Those that remain (mostly caused by #399) will require changes to our models and must be fixed elsewhere.

Thanks a lot! :)

If you're able to test the validator on this branch again and report any further issues before we review it, that would be great!

I missed this train, but I will open new issues should any further problems occur.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
priority/high Issue or PR with a consensus of high priority validator Related to the OPTIMADE validator
Projects
None yet
3 participants