-
Notifications
You must be signed in to change notification settings - Fork 213
Make sure cached easyconfigs don't get modifed #4818
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
base: develop
Are you sure you want to change the base?
Conversation
…tances" This reverts commit 3836140.
This reverts commit 5f04b7b.
The `__deepcopy__` needs to be very generic to avoid misleading results by not copying all (possibly changed) attributes. So leave that alone and use `ec.copy()` on the `'ec'` key directly in the cache code.
Rebased |
|
||
def _copy_ec_dict(easyconfig): | ||
"""Copy an easyconfig dict as (initially) parsed""" | ||
ec = easyconfig.pop('ec') # Don't copy this via deepcopy |
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.
Comment should be clarified: why not
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.
Done: We need ec.copy
"""Copy an easyconfig dict as (initially) parsed""" | ||
ec = easyconfig.pop('ec') # Don't copy this via deepcopy | ||
try: | ||
new_easyconfig = copy.deepcopy(easyconfig) # Copy the rest of the dict |
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.
Can you clarify why this is in a try
?
What if this fails? Then new_easyconfig
will be undefined, and we'll get a nasty crash, no?
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 is a try-finally. So it will still propagate all errors. The only difference is that in all cases ec
(removed above) is put back to the original easyconfig
The type that is cached is a dictionary containing the EasyConfig in the
"ec"
key. Hence we end up invokingdict.copy
notec.copy
This results in not making independent copies and hence modifications affect all references even those gotten later
Revert 3836140 which introduced the issue
Our current
EasyConfig.copy
method effectively parses the EasyConfig text again invoking e.g. theparse_hook
again.I guess
__deepcopy__
needs to be more smart than this to not also miss attributes set after the construction. Hence I left that out and just usedec.copy()
as was likely intended by the above commit. It just needs to be done on the EasyConfig instance while the dict itself can be deep-copied if it doesn't contain the easyconfig.