-
Notifications
You must be signed in to change notification settings - Fork 189
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
Conversation
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.
thanks for this fix @unkcpz !
I have just one request, namely to overwrite the setter instead of introducing a new function:
aiida-core/aiida/orm/nodes/node.py
Lines 221 to 227 in 5e26bac
@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.
db7889a
to
498ef65
Compare
It should be right now. yeah! |
And I search the whole package without finding |
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.
thanks @unkcpz , some final minor requests
@@ -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: |
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.
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
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.
I'll remove the argument, it will make label
setter complex otherwise.
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.
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
?
498ef65
to
c505bc2
Compare
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 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: |
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.
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
c505bc2
to
7462187
Compare
done ;-) thanks for reviewing @ltalirz |
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.
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.
the label validate is test in here
it call the label setter, so it sort of being tested I think.
|
Right - it wasn't tested before but now it is. Great! |
In fact the validation only works when the whole code config is passed in. which means if user type |
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.
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) |
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.
This should have been just a ValuError
. The InputValidationError
is intended for use in CalcJob.prepare_for_submission
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.
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:
aiida-core/aiida/orm/querybuilder.py
Line 141 in 09cb6cb
raise InputValidationError('I do not know what to do with {}'.format(cls)) |
Do all of these uses have to be replaced?
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.
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 |
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.
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.
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.
I would deprecate this for all classes but didn't want to ask jason to do this in this PR.
Sounds reasonable?
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.
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
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.
Ok, I'll revert this deprecation at some point.
Prevent users from using '@' when naming the code when calling
verdi code setup
.Not just make this validation in
verdi code relabel