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

Fix last key detection in pillar.pepa`key_value_to_tree` #50750

Merged
merged 1 commit into from Dec 10, 2018

Conversation

Projects
None yet
3 participants
@bewing
Copy link
Contributor

commented Dec 5, 2018

salt.pillar.pepa.key_value_to_tree() only checks the name of the key when attempting
to identify the last key in a flattened key. This can lead to strange
behavior when the final key name also occurs earlier in the flatkey.

This change explicitly checks that we are the final key in flatkey
prior to setting value. Test included.

Also see mickep76/pepa#11 and mickep76/pepa#12

What does this PR do?

Fix an issue with key processing in the pepa pillar module

What issues does this PR fix or reference?

mickep76/pepa#11 and mickep76/pepa#12

Previous Behavior

In [1]: import collections

In [2]: import salt.pillar.pepa as pepa

In [3]: data = collections.OrderedDict([('foo..bar..foo', True), ('foo..bar..baz', True)])

In [4]: pepa.key_value_to_tree(data)
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-4-f64c7011dc9a> in <module>()
----> 1 pepa.key_value_to_tree(data)

/mnt/c/Users/bewing/PycharmProjects/salt/salt/pillar/pepa/__init__.pyc in key_value_to_tree(data, delimiter)
     28                 t[key] = value
     29             else:
---> 30                 t = t.setdefault(key, {})
     31     return tree
     32

AttributeError: 'bool' object has no attribute 'setdefault'

New Behavior

In [1]: import collections

In [2]: import salt.pillar.pepa as pepa

In [3]: data = collections.OrderedDict([('foo..bar..foo', True), ('foo..bar..baz', True)])

In [4]: pepa.key_value_to_tree(data)
Out[4]: {'foo': {'bar': {'baz': True, 'foo': True}}}

Tests written?

Yes

Commits signed with GPG?

Yes

@bewing bewing requested a review from saltstack/team-core as a code owner Dec 5, 2018

Fix last key detection in pepa key_value_to_tree
pepa.key_value_to_tree only checks the name of the key when attempting
to identify the last key in a flattened key.  This can lead to strange
behavior when the final key name also occurs earlier in the flatkey.

This change explicitly checks that we are the final key in flatkey
prior to setting value.  Test included.

Also see mickep76/pepa#11 and mickep76/pepa#12

@bewing bewing force-pushed the bewing:pepa12 branch from d36a05b to 9931a41 Dec 5, 2018

@terminalmage terminalmage merged commit dcdb9b2 into saltstack:2017.7 Dec 10, 2018

7 of 10 checks passed

jenkins/pr/py2-centos-7 The py2-centos-7 job has failed
Details
jenkins/pr/py2-ubuntu-1604 The py2-ubuntu-1604 job has failed
Details
jenkins/pr/py3-centos-7 The py3-centos-7 job has failed
Details
WIP Ready for review
Details
continuous-integration/jenkins/pr-merge This commit looks good
Details
jenkins/pr/docs The docs job has passed
Details
jenkins/pr/lint Python lint test has passed
Details
jenkins/pr/py2-windows-2016 The py2-windows-2016 job has passed
Details
jenkins/pr/py3-ubuntu-1604 The py3-ubuntu-1604 job has passed
Details
jenkins/pr/py3-windows-2016 The py3-windows-2016 job has passed
Details

@bewing bewing deleted the bewing:pepa12 branch Dec 10, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.