codeant-ai-for-open-source[bot] commented on code in PR #42752:
URL: https://github.com/apache/superset/pull/42752#discussion_r3718093918
##########
superset/models/helpers.py:
##########
@@ -4096,6 +4096,17 @@ def get_sqla_query( # pylint:
disable=too-many-arguments,too-many-locals,too-ma
else:
cond = is_null_cond
else:
+ # Normalize mixed int/float values before binding,
since
+ # SQLAlchemy may infer the bind parameter type from the
+ # first element and silently truncate other values
+ # (see #33206)
+ if target_generic_type ==
utils.GenericDataType.NUMERIC and any(
+ isinstance(v, float) for v in eq
+ ):
+ eq = [
+ float(v) if isinstance(v, (int, float)) else v
+ for v in eq
+ ]
Review Comment:
Agreed—the current conversion can corrupt integers above `2**53`, so this
should not be fixed by converting the original values to `float`.
A safer approach is to avoid mixing bind types altogether: keep integer
values in one `IN` predicate and floating-point values in another, then combine
them with `OR`:
```python
if (
target_generic_type == utils.GenericDataType.NUMERIC
and any(type(v) is float for v in eq)
and any(type(v) is int for v in eq)
):
integer_values = [v for v in eq if type(v) is int]
float_values = [v for v in eq if type(v) is float]
cond = or_(
sqla_col.in_(integer_values),
sqla_col.in_(float_values),
)
else:
cond = sqla_col.in_(eq)
```
This preserves values such as `9007199254740993` as integers while ensuring
the decimal values are bound as floats. The regression test should also include
a large integer mixed with a fractional value to verify that exact integer
precision is retained.
--
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]