-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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 complex grain #52710
Fix complex grain #52710
Conversation
This commit will make it so that grains that are lists of complex objects will be flattened ensuring that comparisons can be made Fixes #39875
@mickenordin, thanks for your PR! By analyzing the history of the files in this pull request, we identified @ryan-lane and @tkwilliams to be potential reviewers. |
Hi! Thanks for the PR! I think you either meant to make this PR against a different branch or you want to rebase your changes against develop. If you need any pointers I'm happy to help! |
Hi, you are probably right. I started to make a clean PR from my fork to
development, but then I read your development guidelines and tried to
follow the instructions there...
This is a simple fix in a file that has been untuched for a long time. What
is the best way to fix this PR?
Den fre 26 apr. 2019 16:22Wayne Werner <notifications@github.com> skrev:
… Hi! Thanks for the PR!
I think you either meant to make this PR against a different branch or you
want to rebase your changes against develop. If you need any pointers I'm
happy to help!
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#52710 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/AAJY6JRKQB2PIMSFUVFFZJLPSMF3DANCNFSM4HIV7RVA>
.
|
@mickenordin If you've just tried to merge into the wrong branch you can go to the top right and click "edit" and then change what branch you're trying to merge into (probably 2018.3 is my guess). If that's not right, let me know where it belongs, and where you branched from, and I can help you rebase or cherry pick your changes. |
@waynew thank you very much, now it looks cleaner I think :) |
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.
Thanks for the PR! Could you update the function definition, as well as add some tests?
tests/unit/states/test_grains.py
would be a good place to add (or update) tests for this.
salt/states/grains.py
Outdated
flatten(subli, flattened) | ||
else: | ||
flattened.append(frozenset(subli)) | ||
return set(flattened) |
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.
Would it be better to just use set
here? The default arg definitely should be changed, though.
I'm thinking something like:
def flatten(li, flattened=None):
flattened = flattened or set()
for subli in li:
if type(subli) == list:
flattened.update(flatten(subli))
else:
flattened.add(frozenset(subli))
return flattened
I'm not entirely certain that's the best approach either, 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.
Great, I will fix those things :)
@waynew thank you for you patiens and your help. I have now fixed all lint errors, added a test that uses the function and added comments and over all tried to make the code more clear and precise. |
What is the next step for this PR? Is there a process for merging or is more review needed? |
@mickenordin shouldn't be - just keep getting changes before we can merge it in 😑 I'll keep my eye out today |
🎉 |
[master] Porting #52710 to master
What does this PR do?
If a grain is a list of complex objects, grains.py is unable to compare the currently set grain to the potentially new one. Instead it fails with TypeError: unhashable type: 'dict' (might be something else aswell depending on what you are trying to set as a grain). This PR will make it so that a list grain that contains complex objects can be compared via the function make_hashable.
What issues does this PR fix or reference?
issue #39875
Tests written?
Yes, in tests/unit/states/test_grains.py there is a test called "test_make_hashable"
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.