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


##########
superset/key_value/types.py:
##########
@@ -113,16 +113,33 @@ 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")

Review Comment:
   Agreed. `encode` now passes `allow_nan=True, ignore_nan=False`, so 
non-finite floats round-trip as before. Added a test.



-- 
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