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

Compat cmp dict fix #58729

Merged
merged 7 commits into from Oct 28, 2022

Conversation

11chrisadams11
Copy link
Contributor

@11chrisadams11 11chrisadams11 commented Oct 13, 2020

What does this PR do?

When passed 2 dicts, the cmp function would fail with a TypeError of "'>' not supported between instances of 'dict' and 'dict'\n". This change adds a check for dict types, compares them with ==, and returns a 0 or -1.

What issues does this PR fix or reference?

Using the boto_cfn state failed with Python 3 as it was trying to compare 2 dicts using compat.cmp

Previous Behavior

The boto_cfn state would fail with the following stack trace:

An exception occurred in this state: Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/salt/state.py", line 2154, in call
       *cdata["args"], **cdata["kwargs"]
  File "/usr/lib/python3/dist-packages/salt/loader.py",
    line 2087, in wrapper
    return f(*args, **kwargs)
  File "/usr/lib/python3/dist-packages/salt/states/boto_cfn.py",
    line 199, in present
    compare = salt.utils.compat.cmp(template, _template_body)

  File "/usr/lib/python3/dist-packages/salt/utils/compat.py", line 66, in cmp
     return (x > y) - (x < y)
TypeError: '>' not supported between instances of 'dict' and 'dict'

New Behavior

The state completes successfully

Merge requirements satisfied?

[NOTICE] Bug fixes or features added to Salt require tests.

Commits signed with GPG?

No

Please review Salt's Contributing Guide for best practices.

See GitHub's page on GPG signing for more information about signing commits with GPG.

@11chrisadams11 11chrisadams11 requested a review from a team as a code owner October 13, 2020 22:15
@11chrisadams11 11chrisadams11 requested review from twangboy and removed request for a team October 13, 2020 22:15
@ghost ghost requested a review from waynew October 13, 2020 22:15
Copy link
Contributor

@waynew waynew left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @11chrisadams11 thanks for the PR! This looks mostly great!

However - even (or especially?) for a change this small we are requiring tests. Should be just a couple of simple cases:

  • - if x and y are equivalent (or copy) dicts, cmp should return 0
  • - if x and y are not equivalent dicts, cmp should return -1 (maybe just do cmp(x, y), cmp(y, x), and expected_result = -1; assert result_one == result_two == expected_result
  • - if x is a dict and y is not, or x is not and y is, ValueError (or TypeError?) should be raised.

Also, this will need a changelog entry, probably Fixed salt.utils.compat.cmp to work with dictionaries or something to that effect.

HTH!

@11chrisadams11
Copy link
Contributor Author

Sounds good. I wasn't sure if a test was required since there was not an existing one. I will get it added.

@11chrisadams11
Copy link
Contributor Author

I have added tests for my changes to compat.cmp, and added a changelog file. Let me know if there is anything else needed.

Thanks

@waynew
Copy link
Contributor

waynew commented Nov 6, 2020

Looks like a couple of test failures @11chrisadams11, mind looking into those? For pre-commit if you click on that and then check the console output it will tell you what's wrong. The freebsd122 isn't required so can probably be ignored - doesn't look like it's even able to find any image (but merging in the latest changes from the master branch will probably sort things)

@11chrisadams11
Copy link
Contributor Author

I made the changes required by the pre-commit check, and everything has passed now.

@11chrisadams11
Copy link
Contributor Author

All checks have passed now. Is there anything else needed from me for this?

waynew
waynew previously approved these changes Dec 4, 2020
Copy link
Contributor

@waynew waynew left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚀

11chrisadams11 and others added 7 commits October 27, 2022 16:43
When passed 2 dicts, the cmp function would fail with a TypeError of "'>' not supported between instances of 'dict' and 'dict'\n". This change adds a check for dict types and compares them with ==.
Copy link
Contributor

@twangboy twangboy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved tests to pytests and rebased... looks good

@garethgreenaway garethgreenaway merged commit 93f871d into saltstack:master Oct 28, 2022
@11chrisadams11 11chrisadams11 deleted the compat_cmp_dict_fix branch November 12, 2022 19:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
boto AWS wrapper modules
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants