rusackas commented on code in PR #45761:
URL: https://github.com/apache/superset/pull/45761#discussion_r4409196773


##########
superset/key_value/types.py:
##########
@@ -113,16 +113,38 @@ def encode(self, value: Any) -> bytes: ...
     def decode(self, value: bytes) -> Any: ...
 
 
+def _contains_bytes(value: Any) -> bool:
+    """Whether ``value`` is, or nests, a raw bytes-like object."""
+    if isinstance(value, (bytes, bytearray, memoryview)):
+        return True
+    if isinstance(value, dict):
+        return any(_contains_bytes(k) or _contains_bytes(v) for k, v in 
value.items())
+    if isinstance(value, (list, tuple, set, frozenset)):
+        return any(_contains_bytes(v) for v in value)
+    return False
+
+
 class JsonKeyValueCodec(KeyValueCodec):
     def encode(self, value: dict[Any, Any]) -> bytes:
+        # JSON has no binary type; bytes, top-level or nested, must not be
+        # silently stringified
+        if _contains_bytes(value):
+            raise KeyValueCodecEncodeException("Cannot JSON-encode a bytes 
value")
         try:
-            return bytes(json.dumps(value), encoding="utf-8")
+            # keep NaN/Infinity round-trippable, as stdlib json did, rather 
than
+            # coercing them to null
+            return bytes(
+                json.dumps(value, allow_nan=True, ignore_nan=False),

Review Comment:
   Not that I can find. I went through the in-tree callers of 
`JsonKeyValueCodec`/`MarshmallowKeyValueCodec` (permalinks, locks, OAuth2 
state, screenshots, extension storage, etc.) and they all store plain 
dicts/lists/scalars, none a `namedtuple`. So I am treating the `namedtuple` 
encoding difference as an accepted edge, not something to preserve.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to