Skip to content
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

Merged
merged 1 commit into from
Dec 5, 2018

Conversation

ganeshrn
Copy link
Member

@ganeshrn ganeshrn commented Dec 4, 2018

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
  • Bugfix Pull Request
COMPONENT NAME

module_utils/network/common/utils.py

ADDITIONAL INFORMATION

@@ -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])
Copy link
Contributor

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....

Copy link
Member Author

@ganeshrn ganeshrn Dec 4, 2018

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.

Copy link
Contributor

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.

@ansibot
Copy link
Contributor

ansibot commented Dec 4, 2018

@ansibot ansibot added affects_2.7 This issue/PR affects Ansible v2.7 backport This PR does not target the devel branch. bug This issue/PR relates to a bug. core_review In order to be merged, this PR must follow the core review workflow. networking Network category support:community This issue/PR relates to code supported by the Ansible community. support:network This issue/PR relates to code supported by the Ansible Network Team. needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR. and removed core_review In order to be merged, this PR must follow the core review workflow. needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR. labels Dec 4, 2018
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
ganeshrn added a commit to ganeshrn/ansible that referenced this pull request Dec 5, 2018
*  Based on review comments for PR ansible#49474 change the check
   for isinstance from `dict` to `Mapping`
@ansibot ansibot added needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR. and removed core_review In order to be merged, this PR must follow the core review workflow. labels Dec 5, 2018
@abadger abadger merged commit 799f8e9 into ansible:stable-2.7 Dec 5, 2018
@abadger
Copy link
Contributor

abadger commented Dec 5, 2018

Merged for 2.7.5. Thanks!

kbreit pushed a commit to kbreit/ansible that referenced this pull request Jan 11, 2019
*  Based on review comments for PR ansible#49474 change the check
   for isinstance from `dict` to `Mapping`
@ansible ansible locked and limited conversation to collaborators Jul 22, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
affects_2.7 This issue/PR affects Ansible v2.7 backport This PR does not target the devel branch. bug This issue/PR relates to a bug. needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR. networking Network category support:community This issue/PR relates to code supported by the Ansible community. support:network This issue/PR relates to code supported by the Ansible Network Team.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants