-
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
CalcJobResultManager
: fix bug that broke tab completion
#4187
CalcJobResultManager
: fix bug that broke tab completion
#4187
Conversation
Codecov Report
@@ Coverage Diff @@
## develop #4187 +/- ##
===========================================
+ Coverage 78.94% 78.97% +0.03%
===========================================
Files 467 467
Lines 34508 34512 +4
===========================================
+ Hits 27240 27253 +13
+ Misses 7268 7259 -9
Continue to review full report at Codecov.
|
@@ -97,17 +97,17 @@ def __getattr__(self, name): | |||
""" | |||
try: | |||
return self.get_results()[name] | |||
except AttributeError: | |||
except KeyError: |
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 think we need to guard also for any exception that can happen in get_results
, both here and below.
I found at least two possibilities, both a ValueError
:
ValueError: cannot load results because process class cannot be loaded: no process type for CalcJobNode<None>: cannot recreate process class
ValueError: cannot load results as the default node could not be retrieved: no neighbor with the label output_parameters found
I am not sure if there is still some case if an AttributeError can still be raised.
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.
For tests, in the first case I just created an unstored CalcJobNode()
; in the second one, a calculation that excepted and hand no output node.
""" | ||
try: | ||
return self.get_results()[name] | ||
except AttributeError: | ||
raise AttributeError("Default result node<{}> does not contain key '{}'".format(self._result_node.pk, name)) | ||
except KeyError: |
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.
Also here
For tab-completion to work properly, the `__getattr__` method need to properly return an `AttributeError` if the corresponding attribute does not exist, however, it was accidentally raising a `KeyError` since the implementation caught an `AttributeError` but the dereferencing was using `__getitem__` so would never raise an `AttributeError`. Likewise, the `__getitem__` implementation was incorrectly returning an `AttributeError` instead of a `KeyError` making it behave different from any other mapping-like data structure.
8ceb61f
to
c7e27e2
Compare
Fixes #4184
For tab-completion to work properly, the
__getattr__
method need toproperly return an
AttributeError
if the corresponding attribute doesnot exist, however, it was accidentally raising a
KeyError
since theimplementation caught an
AttributeError
but the dereferencing wasusing
__getitem__
so would never raise anAttributeError
.Likewise, the
__getitem__
implementation was incorrectly returning anAttributeError
instead of aKeyError
making it behave different fromany other mapping-like data structure.