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

validate label string at code setup stage #3793

Merged
merged 2 commits into from
Feb 25, 2020

Conversation

unkcpz
Copy link
Member

@unkcpz unkcpz commented Feb 24, 2020

Prevent users from using '@' when naming the code when calling verdi code setup.
Not just make this validation in verdi code relabel

Copy link
Member

@ltalirz ltalirz 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 fix @unkcpz !

I have just one request, namely to overwrite the setter instead of introducing a new function:

@label.setter
def label(self, value):
"""Set the label.
:param value: the new value to set
"""
self.backend_entity.label = value

Your setter should first do the validation and then call the setter of the superclass.

@unkcpz
Copy link
Member Author

unkcpz commented Feb 24, 2020

It should be right now. yeah!

@unkcpz
Copy link
Member Author

unkcpz commented Feb 24, 2020

And I search the whole package without finding raise_error being set, so I remove this parameter. Hope it won't be a problem.

Copy link
Member

@ltalirz ltalirz left a comment

Choose a reason for hiding this comment

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

thanks @unkcpz , some final minor requests

aiida/orm/nodes/data/code.py Show resolved Hide resolved
@@ -131,21 +152,14 @@ def relabel(self, new_label, raise_error=True):
if new_label.endswith(suffix):
new_label = new_label[:-len(suffix)]

if '@' in new_label:
msg = "Code labels must not contain the '@' symbol"
if raise_error:
Copy link
Member

@ltalirz ltalirz Feb 24, 2020

Choose a reason for hiding this comment

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

Ok to deprecate it - in this case please put in the docstring of the function something like

.. deprecated:: 1.2.0
            Will be removed in `v2.0.0`. Use `try/except` instead.

for the raise_error argument

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'll remove the argument, it will make label setter complex otherwise.

Copy link
Member

Choose a reason for hiding this comment

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

What you've done here is fine (leave the argument for the moment but don't do anything with it).
Can you still put the deprecation warning about the raise_error argument into the docstring of relabel?

aiida/orm/nodes/data/code.py Show resolved Hide resolved
aiida/orm/utils/builders/code.py Outdated Show resolved Hide resolved
Copy link
Member

@ltalirz ltalirz left a comment

Choose a reason for hiding this comment

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

looks good, just one thing left to do

@@ -131,21 +152,14 @@ def relabel(self, new_label, raise_error=True):
if new_label.endswith(suffix):
new_label = new_label[:-len(suffix)]

if '@' in new_label:
msg = "Code labels must not contain the '@' symbol"
if raise_error:
Copy link
Member

Choose a reason for hiding this comment

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

What you've done here is fine (leave the argument for the moment but don't do anything with it).
Can you still put the deprecation warning about the raise_error argument into the docstring of relabel?

add deprecate info for raise_error in function relabel
@unkcpz
Copy link
Member Author

unkcpz commented Feb 25, 2020

done ;-) thanks for reviewing @ltalirz

Copy link
Member

@ltalirz ltalirz left a comment

Choose a reason for hiding this comment

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

Thanks @unkcpz , that seems good to go.

One thing I just noticed - there seems to be no test of this either...
Would be good to add one, but I'm ok to merge without it as well.

@unkcpz
Copy link
Member Author

unkcpz commented Feb 25, 2020

the label validate is test in here

def test_relabel_code_full_bad(self):

it call the label setter, so it sort of being tested I think.

@ltalirz
Copy link
Member

ltalirz commented Feb 25, 2020

Right - it wasn't tested before but now it is. Great!

@unkcpz
Copy link
Member Author

unkcpz commented Feb 25, 2020

In fact the validation only works when the whole code config is passed in. which means if user type @ in the label interactively will see the exception at the end of config stage.
But I think that needs to be sorted out separately.

@ltalirz ltalirz merged commit 67d4504 into aiidateam:develop Feb 25, 2020
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 @unkcpz . I unfortunately missed the review window, but I have one comment and a question.

"""
if '@' in str(value):
msg = "Code labels must not contain the '@' symbol"
raise InputValidationError(msg)
Copy link
Contributor

Choose a reason for hiding this comment

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

This should have been just a ValuError. The InputValidationError is intended for use in CalcJob.prepare_for_submission

Copy link
Member

Choose a reason for hiding this comment

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

Sorry I didn't see this - this code is just copy-pasted from where it was before.
There are a lot of places in aiida-core where this error is used that have nothing to do with prepare_for_submission:

raise InputValidationError('I do not know what to do with {}'.format(cls))

Do all of these uses have to be replaced?

Copy link
Contributor

Choose a reason for hiding this comment

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

I would say so yes, but that would be a breaking change. The InputValidationError is not a subclass of ValueError which is what one would expect for these kinds of errors. I will open an issue to address this for 2.0

self.label = new_label

def get_description(self):
"""Return a string description of this Code instance.

:return: string description of this Code instance

.. deprecated:: 1.2.0
Copy link
Contributor

Choose a reason for hiding this comment

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

Why is this deprecated? Almost all of the ORM classes have get_description. If we are going for a property, we should try to be consistent and do this everywhere.

Copy link
Member

Choose a reason for hiding this comment

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

I would deprecate this for all classes but didn't want to ask jason to do this in this PR.
Sounds reasonable?

Copy link
Contributor

Choose a reason for hiding this comment

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

I am not sure if we really should replace get_description for description. The reason that both exist is that description is understood to return the value stored in the description column and get_description is some compound from various columns/attributes. We might be able to find another name for get_description to reduce confusion, but in any case I think it should be done in a consistent way across the code and not just in one place

Copy link
Member

Choose a reason for hiding this comment

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

Ok, I'll revert this deprecation at some point.

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