Skip to content

[master] Fixed issue where dictionary key not exists relied on exception - #64018

Closed
tgriffitts-ns wants to merge 3 commits into
saltstack:masterfrom
tgriffitts-ns:Issue-64017-salt-grain-management-fix
Closed

tgriffitts-ns wants to merge 3 commits into
saltstack:masterfrom
tgriffitts-ns:Issue-64017-salt-grain-management-fix

Conversation

@tgriffitts-ns

@tgriffitts-ns tgriffitts-ns commented Apr 3, 2023 •

Copy link
Copy Markdown

What does this PR do?

It changes the old logic which uses an exception to check if a dictionary key does not exist. This logic is no longer valid. The new YAML loader creates dicts which create and return a default empty value object for keys if they do not yet exist in the dictionary. An exception is no longer thrown if the key does not exist. This patch simply checks if the key exists rather than depending on an exception being thrown if it does not.

What issues does this PR fix or reference?

Fixes:
#64017

Previous Behavior

Lots of bugs are caused by this old code. It manifests when setting multiple salt grains under the same hierarchy in a single highstate

New Behavior

All works as expected

Merge requirements satisfied?

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

Commits signed with GPG?

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

@tgriffitts-ns
tgriffitts-ns requested a review from a team as a code owner April 3, 2023 22:38
@tgriffitts-ns
tgriffitts-ns requested review from MKLeb and removed request for a team April 3, 2023 22:38
@welcome

welcome Bot commented Apr 3, 2023

Copy link
Copy Markdown

Hi there! Welcome to the Salt Community! Thank you for making your first contribution. We have a lengthy process for issues and PRs. Someone from the Core Team will follow up as soon as possible. In the meantime, here’s some information that may help as you continue your Salt journey.
Please be sure to review our Code of Conduct. Also, check out some of our community resources including:

There are lots of ways to get involved in our community. Every month, there are around a dozen opportunities to meet with other contributors and the Salt Core team and collaborate in real time. The best way to keep track is by subscribing to the Salt Community Events Calendar.
If you have additional questions, email us at [email protected]. We’re glad you’ve joined our community and look forward to doing awesome things with you!

@salt-project-bot-prod-environment salt-project-bot-prod-environment Bot changed the title Fixed issue where dictionary key not exists relied on exception [master] Fixed issue where dictionary key not exists relied on exception Apr 3, 2023

@tgriffitts-ns tgriffitts-ns left a comment •

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

comment removed

Comment thread salt/utils/data.py

@tgriffitts-ns tgriffitts-ns Apr 7, 2023 •

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

An ignore-whitespace-changes diff on this delta shows much more clearly what is being changed:

@@ -850,8 +850,9 @@
                         return default
         else:
             try:
+                if each in ptr:
                     ptr = ptr[each]
-            except KeyError:
+                else:
                     # Late import to avoid circular import
                     import salt.utils.args

The whitespaces changes are to indent the existing block of lines, unchanged, which are now under the new if each in ptr: statement.

@twangboy twangboy left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Could you please write some tests and add a changelog.

@twangboy twangboy linked an issue Apr 28, 2023 that may be closed by this pull request
@s0undt3ch s0undt3ch added the backport:3006.x Backport PR to 3006.x branch label May 2, 2023
@s0undt3ch s0undt3ch added the needs-testcase PR needs test cases written, or the issue is about a bug/feature that needs test cases label Aug 22, 2023
@s0undt3ch
s0undt3ch temporarily deployed to ci August 22, 2023 09:20 — with GitHub Actions Inactive
@s0undt3ch
s0undt3ch temporarily deployed to ci August 22, 2023 09:20 — with GitHub Actions Inactive
@s0undt3ch
s0undt3ch temporarily deployed to ci August 22, 2023 09:20 — with GitHub Actions Inactive
@s0undt3ch
s0undt3ch temporarily deployed to ci August 22, 2023 09:20 — with GitHub Actions Inactive
@s0undt3ch
s0undt3ch temporarily deployed to ci August 22, 2023 09:38 — with GitHub Actions Inactive
@s0undt3ch
s0undt3ch temporarily deployed to ci August 22, 2023 09:41 — with GitHub Actions Inactive
@s0undt3ch
s0undt3ch temporarily deployed to ci August 22, 2023 10:40 — with GitHub Actions Inactive
@s0undt3ch
s0undt3ch temporarily deployed to ci August 22, 2023 10:40 — with GitHub Actions Inactive
@s0undt3ch
s0undt3ch temporarily deployed to ci August 22, 2023 10:40 — with GitHub Actions Inactive
@s0undt3ch
s0undt3ch temporarily deployed to ci August 22, 2023 10:40 — with GitHub Actions Inactive
@s0undt3ch
s0undt3ch temporarily deployed to ci August 22, 2023 10:40 — with GitHub Actions Inactive
@s0undt3ch
s0undt3ch temporarily deployed to ci August 22, 2023 10:40 — with GitHub Actions Inactive
@dwoz

dwoz commented Dec 17, 2023

Copy link
Copy Markdown
Contributor

Closing this due to inactivity. Anyone should feel free to re-open it if they want to see it through to the end in one release cycle.

@tgriffitts-ns We can re-open this if you want to get it into a release.

This branch was previously deployed

1 inactive deployment
ci — 5eb9e7ea Deployed Aug 22, 2023 by s0undt3ch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport:3006.x Backport PR to 3006.x branch needs-testcase PR needs test cases written, or the issue is about a bug/feature that needs test cases

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Broken logic in grains management with new default YAML loader

4 participants