Skip to content

[3006.x] Ensure dunder global NamedLoaderContext obj's value() is used, when passing outside of execution modules - #64055

Merged
garethgreenaway merged 9 commits into
saltstack:3006.xfrom
dmurphy18:fix_62477
Apr 26, 2023

Conversation

@dmurphy18

@dmurphy18 dmurphy18 commented Apr 12, 2023 •

Copy link
Copy Markdown
Contributor

What does this PR do?

Checks that the NamedLoaderContext object used does not generate a None before attempting to use it to create a dictionary

What issues does this PR fix or reference?

Fixes: #62477

Previous Behavior

The code would throw an exception due to effectively executing dict(None) from a NamedLoaderContext object.

New Behavior

Ensure that NamedLoaderContext objects used with dunder globals, typically grains and pillar, have their 'value(). used to pass their contents rather than the NamedLoaderContext object when the value is passed to other modules, for example: pillar, utils, etc.

Merge requirements satisfied?

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

Commits signed with GPG?

Yes

Please review Salt's Contributing Guide for best practices.

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

@dmurphy18 dmurphy18 added the Sulfur v3006.0 release code name and version label Apr 12, 2023
@dmurphy18 dmurphy18 added this to the Sulfur v3006.0 milestone Apr 12, 2023
@dmurphy18
dmurphy18 requested a review from a team as a code owner April 12, 2023 01:21
@dmurphy18
dmurphy18 requested review from MKLeb and removed request for a team April 12, 2023 01:21
@salt-project-bot-prod-environment salt-project-bot-prod-environment Bot changed the title Check NamedLoaderContext obj is not None, before creating a dictionary [3006.x] Check NamedLoaderContext obj is not None, before creating a dictionary Apr 12, 2023
dwoz
dwoz previously requested changes Apr 12, 2023
Comment thread salt/payload.py Resolved
Comment thread changelog/62477.fixed.md Resolved
Comment thread salt/payload.py Resolved
@dmurphy18
dmurphy18 requested review from dwoz and s0undt3ch April 12, 2023 14:43
Comment thread changelog/62477.fixed.md Resolved
@dmurphy18
dmurphy18 force-pushed the fix_62477 branch 2 times, most recently from 6a02da4 to c0054d8 Compare April 13, 2023 01:01
s0undt3ch
s0undt3ch previously approved these changes Apr 13, 2023
@dmurphy18 dmurphy18 removed the Sulfur v3006.0 release code name and version label Apr 13, 2023
@dmurphy18

Copy link
Copy Markdown
Contributor Author

Moving this to 3006.1, to allow for more time to research NamedLoaderContext issue not containing a loader which results in None.

@dmurphy18
dmurphy18 force-pushed the fix_62477 branch 2 times, most recently from 2d24bc0 to 4c653d8 Compare April 18, 2023 23:10
@dmurphy18
dmurphy18 temporarily deployed to ci April 18, 2023 23:28 — with GitHub Actions Inactive
@dmurphy18 dmurphy18 changed the title [3006.x] Check NamedLoaderContext obj is not None, before creating a dictionary [3006.x] Ensure dunder global NamedLoaderContext obj's value() is used, when passing outside of execution modules Apr 18, 2023
@dmurphy18
dmurphy18 temporarily deployed to ci April 19, 2023 00:07 — with GitHub Actions Inactive
@dmurphy18
dmurphy18 temporarily deployed to ci April 19, 2023 00:07 — with GitHub Actions Inactive
@dmurphy18
dmurphy18 dismissed dwoz’s stale review April 25, 2023 00:15

See the new code changes

dwoz
dwoz previously approved these changes Apr 25, 2023

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

This just needs a regression test.

@dmurphy18

Copy link
Copy Markdown
Contributor Author

Fortunately have one almost written :)
Will polish it off and submit that too

@dmurphy18
dmurphy18 temporarily deployed to ci April 26, 2023 00:51 — with GitHub Actions Inactive
@dmurphy18
dmurphy18 temporarily deployed to ci April 26, 2023 00:51 — with GitHub Actions Inactive
@dmurphy18
dmurphy18 temporarily deployed to ci April 26, 2023 00:52 — with GitHub Actions Inactive
@dmurphy18
dmurphy18 temporarily deployed to ci April 26, 2023 02:39 — with GitHub Actions Inactive
@dmurphy18
dmurphy18 temporarily deployed to ci April 26, 2023 02:39 — with GitHub Actions Inactive
@dmurphy18
dmurphy18 temporarily deployed to ci April 26, 2023 02:39 — with GitHub Actions Inactive
@dmurphy18

Copy link
Copy Markdown
Contributor Author

Test added

@garethgreenaway
garethgreenaway merged commit e25da80 into saltstack:3006.x Apr 26, 2023
@dmurphy18
dmurphy18 deleted the fix_62477 branch March 13, 2024 18:00
dwoz added a commit to dwoz/salt that referenced this pull request Nov 23, 2026
…tack#65504)

salt '*' config.items and similar minion jobs crashed on the master
with AttributeError: 'NoneType' object has no attribute '__iter__'
when a NamedLoaderContext whose value() returned None was included
in the returned payload.  salt.payload.dumps msgpack-encodes any
collections.abc.MutableMapping via dict(obj), which iterates via
__iter__ -> self.value().__iter__().  Off-context, the four mapping-
typed dunders fell back to the construction default of None and
crashed at that dict() call.

Fix at the dunder construction site in salt.loader.dunder: pass
default={} for the mapping-typed dunders (__opts__, __context__,
__pillar__, __grains__).  value() now returns an empty mapping
off-context, honoring the MutableMapping contract the class
advertises.  __file_client__ stays default=None: it is not a
mapping, and None is its documented 'no file client' sentinel.

Reviewers of saltstack#64055 (April 2023) deliberately removed the earlier
NamedLoaderContext branch in salt.payload.dumps and directed the
fix to the loader layer; this change respects that direction.

This branch was previously deployed

1 inactive deployment
ci — be95521b Deployed Apr 26, 2023 by dmurphy18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants