Updated check and return if obj.value() if dict else empty dictionary

This commit is contained in:
David Murphy 2023-04-12 18:59:33 -06:00 committed by Gareth J. Greenaway
parent 8c60ddb291
commit 25e9a5c706
3 changed files with 5 additions and 4 deletions

View file

@ -1 +1 @@
Check NamedLoadedContext mapping is not None, before attempting to create a dictory with it
Check NamedLoadedContext mapping is not None, before attempting to create a dictionary with it

View file

@ -32,7 +32,7 @@ def loader_context(loader):
class NamedLoaderContext(collections.abc.MutableMapping):
"""
A NamedLoaderContext object is injected by the loader providing access to
Salt's 'magic dunders' (__salt__, __utils__, ect).
Salt's 'magic dunders' (__salt__, __utils__, etc).
"""
def __init__(self, name, loader_context, default=None):

View file

@ -166,9 +166,10 @@ def dumps(msg, use_bin_type=False):
elif isinstance(obj, CaseInsensitiveDict):
return dict(obj)
elif isinstance(obj, NamedLoaderContext):
if obj.value() is None:
if isinstance(obj.value(), dict):
return obj.value()
else:
return {}
return dict(obj)
elif isinstance(obj, collections.abc.MutableMapping):
return dict(obj)
# Nothing known exceptions found. Let msgpack raise its own.