-
Notifications
You must be signed in to change notification settings - Fork 23.8k
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
fixes an issue with dict_merge in network utils (#41107) #49474
Conversation
eada9fa
to
f07e6ab
Compare
@@ -275,7 +275,10 @@ def dict_merge(base, other): | |||
if key in other: | |||
item = other.get(key) | |||
if item is not None: | |||
combined[key] = dict_merge(value, other[key]) | |||
if isinstance(other[key], dict): | |||
combined[key] = dict_merge(value, other[key]) |
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.
Shouldn't this be Mapping?
from ansible.module_utils.common._collections_compat import Mapping
[...]
if isinstance(other[key], Mapping):
How deeply nested are your dicts? If they're too deeply nested they'll run into the recursion limit. We can cross that bridge if you start to get bug reports about it though....
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.
Will change it to mapping.
How deeply nested are your dicts?
It depends on how nested the data model is for a particular network device and the data model varies vastly from vendor to vendor so can't say exactly how deeply nested dicts can be.
dict_diff
function for network use case is mainly written to get diff between the candidate configuration (user input or module arg spec) and the running config retrieved from the device when action override
and dict_merge
to merge candidate and running config when action is merge
.
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.
Okay. the default recursionlimit in python is 100 levels. (But it might be set lower if someone has optimized their python build for low memory situations). We'll just have to wait and see if we get any bug reports and fix this then.
This change address a problem where the dict_merge function would fail due to the value being a nested dict. This will now recursively pass the value back through the dict_merge function. Merge to devel ansible#41107 (cherry picked from commit 2a4be27) Update changelog Fix review comments
f07e6ab
to
e48d77b
Compare
* Based on review comments for PR ansible#49474 change the check for isinstance from `dict` to `Mapping`
Merged for 2.7.5. Thanks! |
* Based on review comments for PR ansible#49474 change the check for isinstance from `dict` to `Mapping`
SUMMARY
This change address a problem where the dict_merge function would fail
due to the value being a nested dict. This will now recursively pass
the value back through the dict_merge function.
(cherry picked from commit 2a4be27)
ISSUE TYPE
COMPONENT NAME
module_utils/network/common/utils.py
ADDITIONAL INFORMATION