You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[BUG] binary return data causes tracebacks in many returners #59012
Maybe binary data should be b64 encoded instead of the return data being dropped?
It's probably because the returners were all written for Python 2, where str and bytes are interchangeable, and never updated.
Any state that is still returning bytes should be fixed to return str, but it wouldn't hurt to also allow the returners to handle both.
@dhiltonp@xeacott@danielrobbins there are several of these issues where Python2 expected either strings or bytes and some modules were written with one or the other and likely not both, I created a label, if anyone can create PRs please do. I hope to get most of these work done in Silicon release cycle or at least planned and worked in Silicon and soon after, if there is a global approach (doubtful) we may want to explore it.
This issue still present in 3006.1 right ? Trying to use odbc returner and getting errors like
[WARNING ] Returner unavailable: the JSON object must be str, bytes or bytearray, not 'Row'
TypeError: the JSON object must be str, bytes or bytearray, not 'Row'
A recent salt release (I went from 3006.9 -> 3006.12) added the tok return to all minion payloads, which is encoded, that caused me problems when using the API.
I implemented a local patch on the salt-master to sanitize the data:
--- /opt/saltstack/salt/lib/python3.10/site-packages/salt/utils/json.py.dist 2025-06-16 17:08:27.484890052 +0100
+++ /opt/saltstack/salt/lib/python3.10/site-packages/salt/utils/json.py 2025-06-16 17:19:28.804754435 +0100
@@ -152,6 +152,22 @@
kwargs["ensure_ascii"] = False
return json_module.dump(obj, fp, **kwargs)
+def _sanitize_for_json(obj):
+ """
+ Recursively clean up an object to make it safe for JSON serialization.
+ Non-serializable types are converted to strings.
+ """
+ if isinstance(obj, dict):
+ return {_sanitize_for_json(k): _sanitize_for_json(v) for k, v in obj.items()}
+ elif isinstance(obj, list):
+ return [_sanitize_for_json(v) for v in obj]
+ elif isinstance(obj, tuple):
+ return tuple(_sanitize_for_json(v) for v in obj)
+ elif isinstance(obj, (str, int, float, bool)) or obj is None:
+ return obj
+ else:
+ # Convert non-serializable object to string
+ return str(obj)
def dumps(obj, **kwargs):
"""
@@ -171,4 +187,4 @@
json_module = kwargs.pop("_json_module", json)
if "ensure_ascii" not in kwargs:
kwargs["ensure_ascii"] = False
- return json_module.dumps(obj, **kwargs)
+ return json_module.dumps(_sanitize_for_json(obj), **kwargs)
Activity
OrangeDog commentedon Nov 30, 2020
It's probably because the returners were all written for Python 2, where
strandbytesare interchangeable, and never updated.Any state that is still returning
bytesshould be fixed to returnstr, but it wouldn't hurt to also allow the returners to handle both.sagetherage commentedon Mar 22, 2021
Joe was pulled off of some work in AL for other priorities, moving this to Si release cycle
sagetherage commentedon Mar 22, 2021
@dhiltonp @xeacott @danielrobbins there are several of these issues where Python2 expected either strings or bytes and some modules were written with one or the other and likely not both, I created a label, if anyone can create PRs please do. I hope to get most of these work done in
Siliconrelease cycle or at least planned and worked inSiliconand soon after, if there is a global approach (doubtful) we may want to explore it.amalaguti commentedon Jul 5, 2023
This issue still present in 3006.1 right ? Trying to use odbc returner and getting errors like
[WARNING ] Returner unavailable: the JSON object must be str, bytes or bytearray, not 'Row'
TypeError: the JSON object must be str, bytes or bytearray, not 'Row'
Orlando-Richards commentedon Jun 16, 2025
A recent salt release (I went from 3006.9 -> 3006.12) added the
tokreturn to all minion payloads, which is encoded, that caused me problems when using the API.I implemented a local patch on the salt-master to sanitize the data: