-
Notifications
You must be signed in to change notification settings - Fork 117
[bugfix] Fix deep-copy of _Undefined constant
#2027
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
[bugfix] Fix deep-copy of _Undefined constant
#2027
Conversation
The condition `self.environment is _Undefined` is always `False`, so the error is actually never raised.
|
Can I test this patch? |
jjotero
left a comment
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.
Hi @giordano. Thanks for spotting this.
I have the feeling that the line you changed was correct before. Instead, the definition of _UndefinedType should be as follows:
class _UndefinedType:
'''Used as an initial value for undefined values instead of None.'''
__slots__= ()
def __deepcopy__(self, memo):
return selfThis would ensure that the _Undefined constant will always be the same instance of _UndefinedType regardless of deep copies and so on.
Could you please try this approach instead? Thanks!
|
Hello @giordano, Thank you for updating! Cheers! There are no PEP8 issues in this Pull Request!Do see the ReFrame Coding Style Guide Comment last updated at 2021-06-24 08:51:57 UTC |
ae4f903 to
a52dec5
Compare
|
Yes, I confirm this also does the trick, thanks! |
|
@giordano, thanks. I personally like this change much more. I was about to ask you why not work on the This fix implies that we had a bug because |
|
Also, I wanted to add a test, but I think |
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.
@giordano This test is checking this exact same BuildSystemError. The difference is that the Spack(BuildSystem) instance is deep-copied when you actually run ReFrame, and such deep-copy is not done by the unit test. Hence, the deep-copy
if self.environment is _Undefined:
...compares that self.environment is the same instance of _UndefinedType as _Undefined. But because the build system class has been deep-copied, they are not he same instance and this evaluates to False. This is what overriding the __deepcopy__ method of _UndefinedType fixes.
This being said, we already have a mechanism in place to deal with these types of classes (reframe/core/variables.py) and it probably makes sense to make all these BuildSystem classes use all that machinery too. I'll create an issue to discuss that internally.
Thanks again for spotting the bug!
@victorusu are you happy with the changes?
_Undefined constant
The condition
self.environment is _Undefinedis alwaysFalse, so the erroris actually never raised.
Without this change, I get a much more obscure error message:
With this change I get
which I guess was the point of this check