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

additional validation for cli arguments #3894

Merged
merged 6 commits into from
Apr 13, 2020

Conversation

ltalirz
Copy link
Member

@ltalirz ltalirz commented Apr 6, 2020

fixes #3301
fixes #3596
fixes #3897
fixes #3770

Note: Since existing databases may contain data that does not validate under the new rules, we have not introduced validations for CLI options that would make it impossible to work with existing data (e.g. for the label of nodes, etc.).
Those should be made in a separate PR.

Todo:

@ltalirz ltalirz force-pushed the issue_3301_input_validation branch from 2534ba7 to 4f7e473 Compare April 6, 2020 07:40
Copy link
Contributor

@sphuber sphuber left a comment

Choose a reason for hiding this comment

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

Thanks @ltalirz , few comments and suggestions

aiida/cmdline/params/options/commands/computer.py Outdated Show resolved Hide resolved


class IdentifierParamType(click.ParamType, ABC):
class IdentifierParamType(AlphanumericStringType, ABC):
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think we can make this change. It is true that for the ID and UUID interpretation of the IdentifierParamType the alpha-numeric rules apply, however, the LABEL is currently not restricted to this. By changing this people will no longer be able to load certain entities through their label that contain non-alpha-numeric character

Copy link
Member Author

@ltalirz ltalirz Apr 6, 2020

Choose a reason for hiding this comment

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

Right, consider this more of a "draft" PR (somehow I always realize too late when something is a draft PR and I think one cannot change it afterwards).
I wanted to discuss what the validation of labels should be - both on a global level and for specific labels (computers, codes, ...).

aiida/cmdline/params/types/strings.py Outdated Show resolved Hide resolved
aiida/cmdline/params/types/strings.py Outdated Show resolved Hide resolved
aiida/cmdline/params/types/strings.py Outdated Show resolved Hide resolved
aiida/cmdline/params/types/strings.py Outdated Show resolved Hide resolved
aiida/cmdline/params/types/strings.py Outdated Show resolved Hide resolved
@ltalirz ltalirz force-pushed the issue_3301_input_validation branch 2 times, most recently from ecfd32e to f209092 Compare April 6, 2020 12:02
@ltalirz ltalirz force-pushed the issue_3301_input_validation branch 2 times, most recently from c59c32f to cca6522 Compare April 6, 2020 20:09
@ltalirz ltalirz force-pushed the issue_3301_input_validation branch 3 times, most recently from 09a2508 to a58739e Compare April 13, 2020 13:35
@codecov
Copy link

codecov bot commented Apr 13, 2020

Codecov Report

Merging #3894 into develop will increase coverage by 0.00%.
The diff coverage is 85.52%.

Impacted file tree graph

@@           Coverage Diff            @@
##           develop    #3894   +/-   ##
========================================
  Coverage    78.20%   78.20%           
========================================
  Files          460      460           
  Lines        33982    34027   +45     
========================================
+ Hits         26574    26611   +37     
- Misses        7408     7416    +8     
Flag Coverage Δ
#django 70.23% <81.57%> (+<0.01%) ⬆️
#sqlalchemy 71.09% <85.52%> (+0.01%) ⬆️
Impacted Files Coverage Δ
aiida/cmdline/params/types/strings.py 79.62% <79.62%> (ø)
aiida/cmdline/params/arguments/__init__.py 100.00% <100.00%> (ø)
aiida/cmdline/params/options/commands/computer.py 85.18% <100.00%> (ø)
aiida/cmdline/params/options/commands/setup.py 93.90% <100.00%> (-0.08%) ⬇️
aiida/cmdline/params/options/interactive.py 83.47% <100.00%> (ø)
aiida/cmdline/params/types/identifier.py 89.13% <100.00%> (+0.24%) ⬆️
aiida/cmdline/params/types/plugin.py 89.58% <100.00%> (+0.22%) ⬆️
aiida/cmdline/params/types/profile.py 66.66% <100.00%> (+0.95%) ⬆️
aiida/transports/plugins/local.py 80.46% <0.00%> (+0.25%) ⬆️

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 c74048b...6d18745. Read the comment docs.

@ltalirz ltalirz requested a review from sphuber April 13, 2020 15:05
@ltalirz
Copy link
Member Author

ltalirz commented Apr 13, 2020

@sphuber I think this is ready for review now. See the description of the PR for the list of changes.

Copy link
Contributor

@sphuber sphuber left a comment

Choose a reason for hiding this comment

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

Thanks @ltalirz . Only two comments: the first one is really minor and I only put it there since I though you would anyway have to do a few more touchups, but it seems all is good. There is just one question about making the ProfileParamType validation more strict, which could cause (light) problems for existing profiles. Just wanted to check if you had thought about this

@@ -1,6 +1,6 @@
---
profile: PLACEHOLDER_PROFILE
email: aiida@localhost
Copy link
Contributor

Choose a reason for hiding this comment

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

Not crucial, but since we decided to keep this as allowed, maybe revert it

Copy link
Member Author

Choose a reason for hiding this comment

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

Done!



class ProfileParamType(click.ParamType):
class ProfileParamType(LabelStringType):
Copy link
Contributor

Choose a reason for hiding this comment

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

Here we are making the rules more strict. There might be profiles out there that don't respect the rules of LabelStringType. Those will no longer be able to be used in the CLI. Of course, the profile name can easily be adapted manually in the config.json, just wanted to check if you thought about this. If you are ok with doing this, then also fine by me

Copy link
Member Author

Choose a reason for hiding this comment

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

I'm aware, but I think this change is still reasonable. My arguments:

  • as you say, it's something that can be easily fixed (and it's probably in the best interest of people to do so)
  • it can prevent issues during profile setup, which is the first thing new aiida users do
  • the profile name is not exported, so this does not invalidate any published data

 * Start validating
   * hostnames
   * emails
   * entry point names

 * InteractiveOption: validate empty reply

The `InteractiveOption` of the CLI always allowed users to pass `!` in
order to avoid setting a value, bypassing any further validation that
may be provided by the `type`.

Change this behavior such that entering `!` results in an empty string
being passed further to the `type`. Only if conversion by the type
passes as well should a `None` value be returned.

 * increase code reuse in options
 * move IdentifierParamType back to how it was before
 * add test for verdi code duplicate
   return empty string, if passing `!` into string-type parameters.
with outputting test coverage to the terminal on travis, the test output
becomes increasingly unreadable and it becomes difficult to find the
information on failing tests (which is what one is usually looking for).

 * remove coverage information from test output on travis
 * limit printing of test timings to 50 longest-running tests
@ltalirz ltalirz force-pushed the issue_3301_input_validation branch from 860d3b0 to cb55197 Compare April 13, 2020 19:35
@ltalirz ltalirz force-pushed the issue_3301_input_validation branch from cb55197 to f5b4aa7 Compare April 13, 2020 19:47
@ltalirz ltalirz requested a review from sphuber April 13, 2020 19:52
Copy link
Contributor

@sphuber sphuber left a comment

Choose a reason for hiding this comment

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

Thanks a lot @ltalirz

@sphuber sphuber merged commit 6ea9ecb into aiidateam:develop Apr 13, 2020
@sphuber sphuber deleted the issue_3301_input_validation branch April 13, 2020 20:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants