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


##########
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:
   `superset.utils.json.dumps` defaults to `ignore_nan=True`, so `NaN` and 
`±Infinity` are written as `null` here, whereas stdlib `json` wrote them and 
the new `allow_nan=True` on decode reads them back. A legacy entry like 
`{"limit": Infinity}` now decodes fine but is saved as `{"limit": null}`, and 
`SupersetMetastoreCache.compare_and_set` re-encodes the decoded expected value 
as `null`, so it no longer matches the stored legacy bytes. Should the encode 
call pass `allow_nan=True, ignore_nan=False` to keep non-finite values 
round-trippable, with a test that encodes them?



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