Repository navigation
Conversation
3 tasks done
4 of 9 tasks
twangboy
approved these changes
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.
dwoz
force-pushed
the
dwoz/fix/65504-namedloader-dict-default
branch
from
November 23, 2026 23:46
7ebc751 to
920650f
Compare
This branch was previously deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Supersedes #69644. Resolves #65504.
salt '*' config.itemsand similar minion jobs crashed on the master withAttributeError: 'NoneType' object has no attribute '__iter__'when the returned payload contained aNamedLoaderContextwhosevalue()returnedNone.salt.payload.dumpsmsgpack-encodes anycollections.abc.MutableMappingviadict(obj), which iterates via__iter__ -> self.value().__iter__().Why this fix lives in
salt/loader/dunder.pyand not in the dunders themselvesThe mapping-typed dunders (
__opts__,__context__,__pillar__,__grains__) now passdefault={}tonamed_context().value()returns an empty mapping off-context, honoring theMutableMappingcontract thatNamedLoaderContextadvertises.Reviewers of #64055 (April 2023) deliberately removed an earlier
NamedLoaderContextbranch insalt.payload.dumpsand directed the fix to the loader layer so dunder globals would pass.value()outside execution modules rather than special-casing the serializer. This change respects that direction.__file_client__staysdefault=None: it is not a mapping, andNoneis its documented "no file client" sentinel.Previous iteration
#69644 took a different approach — guarding the seven container-protocol dunders on
NamedLoaderContextitself (__iter__,__len__,__contains__,__getitem__,__setitem__,__delitem__,get). That works but introduces semantics inconsistent withdict(notably__setitem__raisingTypeErrorinstead of creating an entry) and silently masks the real-bug signal of "__opts__wasNonewhere it shouldn't be." This 4-line construction-site fix keeps the invariant thatNamedLoaderContextalways backs a real mapping.Test plan
test_dunder_mapping_globals_default_to_empty_dict— strict regression:__opts__/__context__/__pillar__/__grains__havedefault == {},__file_client__hasdefault is None. Fails without the fix.test_dunder_opts_round_trips_through_payload_off_context— load-bearing scenario:salt.payload.dumpson a payload containingsalt.loader.dunder.__opts__off-context round-trips to{"ctx": {}}. Fails without the fix withAttributeError: 'NoneType' object has no attribute '__iter__'.tests/pytests/unit/loader/test_context.pystill pass.