aminghadersohi commented on code in PR #44219:
URL: https://github.com/apache/superset/pull/44219#discussion_r4012148075


##########
superset/common/query_context_processor.py:
##########
@@ -568,7 +569,10 @@ def get_data(
                 )
             return result or ""
 
-        return df.to_dict(orient="records")
+        # QueryObject post-processing has completed before this materialization
+        # boundary. Canonicalize its trusted missing/non-finite scalar outputs,
+        # while downstream envelope validation still rejects injected infinity.
+        return df_to_records(df, convert_big_integers=False)

Review Comment:
   Fixed in ee59e685f8. The query-context producer now uses the default 
browser-safe integer conversion, and the regression test exercises both the 
producer result and strict JSON browser-wire round trip for `2**53 + 1`.



##########
superset/dataframe.py:
##########
@@ -34,45 +43,54 @@ def _convert_big_integers(val: Any) -> Any:
     :returns: the same value but recast as a string if it was an integer over
         ``JS_MAX_INTEGER``
     """
-    return str(val) if isinstance(val, int) and abs(val) > JS_MAX_INTEGER else 
val
-
-
-def _is_na(val: Any) -> bool:
-    """
-    Check if a value is NA/NaN for scalar values only.
-
-    pd.isna() raises ValueError for arrays/lists, so we catch that case.
-
-    :param val: the value to check
-    :returns: True if the value is NA/NaN, False otherwise
-    """
-    try:
-        return bool(pd.isna(val))
-    except ValueError:
-        # pd.isna raises ValueError for arrays (e.g., lists, dicts from JSON)
-        return False
-
-
-def df_to_records(dframe: pd.DataFrame) -> list[dict[str, Any]]:
+    return str(val) if type(val) is int and abs(val) > JS_MAX_INTEGER else val
+
+
+def _is_trusted_missing_or_nonfinite(value: Any) -> bool:
+    """Recognize producer nulls without consulting object-column hooks."""
+    value_type = type(value)
+    if value_type in _PANDAS_MISSING_TYPES:
+        return True
+    if value_type is Decimal:
+        return not Decimal.is_finite(value)
+    if value_type is float:
+        return not math.isfinite(value)
+    if value_type in _NUMPY_FLOAT_TYPES:
+        return not math.isfinite(float(value))

Review Comment:
   Fixed in ee59e685f8. NumPy floating values are classified with `np.isfinite` 
before conversion, and record materialization preserves `np.longdouble` instead 
of narrowing through Python float. Direct coverage verifies finite `1e400` 
survives while ±inf/NaN become null.



##########
superset/dataframe.py:
##########
@@ -34,45 +43,54 @@ def _convert_big_integers(val: Any) -> Any:
     :returns: the same value but recast as a string if it was an integer over
         ``JS_MAX_INTEGER``
     """
-    return str(val) if isinstance(val, int) and abs(val) > JS_MAX_INTEGER else 
val
-
-
-def _is_na(val: Any) -> bool:
-    """
-    Check if a value is NA/NaN for scalar values only.
-
-    pd.isna() raises ValueError for arrays/lists, so we catch that case.
-
-    :param val: the value to check
-    :returns: True if the value is NA/NaN, False otherwise
-    """
-    try:
-        return bool(pd.isna(val))
-    except ValueError:
-        # pd.isna raises ValueError for arrays (e.g., lists, dicts from JSON)
-        return False
-
-
-def df_to_records(dframe: pd.DataFrame) -> list[dict[str, Any]]:
+    return str(val) if type(val) is int and abs(val) > JS_MAX_INTEGER else val
+
+
+def _is_trusted_missing_or_nonfinite(value: Any) -> bool:
+    """Recognize producer nulls without consulting object-column hooks."""
+    value_type = type(value)
+    if value_type in _PANDAS_MISSING_TYPES:
+        return True
+    if value_type is Decimal:
+        return not Decimal.is_finite(value)
+    if value_type is float:
+        return not math.isfinite(value)
+    if value_type in _NUMPY_FLOAT_TYPES:
+        return not math.isfinite(float(value))
+    return False

Review Comment:
   Fixed in ee59e685f8 with `np.isfinite` on the original NumPy scalar and 
non-narrowing row materialization. Producer/browser-wire regression coverage 
accompanies the direct longdouble test; the focused suite passes (152 tests).



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