Skip to content

fix: Fixed numeric filtering issue in Superset #33222

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 18 additions & 7 deletions superset/models/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -1162,6 +1162,11 @@ def filter_values_handler( # pylint: disable=too-many-arguments # noqa: C901
def handle_single_value(value: Optional[FilterValue]) -> Optional[FilterValue]:
if operator == utils.FilterOperator.TEMPORAL_RANGE:
return value
Comment on lines 1162 to 1164

This comment was marked as resolved.


# Ensure consistent numeric representation
if isinstance(value, (int, float)) and target_generic_type == utils.GenericDataType.NUMERIC:
value = float(value) # Normalize all numeric values to float

if (
isinstance(value, (float, int))
and target_generic_type == utils.GenericDataType.TEMPORAL
Expand All @@ -1174,9 +1179,10 @@ def handle_single_value(value: Optional[FilterValue]) -> Optional[FilterValue]:
db_extra=db_extra,
)
value = literal_column(value)

if isinstance(value, str):
value = value.strip("\t\n")

if (
target_generic_type == utils.GenericDataType.NUMERIC
and operator
Expand All @@ -1185,16 +1191,21 @@ def handle_single_value(value: Optional[FilterValue]) -> Optional[FilterValue]:
utils.FilterOperator.LIKE,
}
):
# For backwards compatibility and edge cases
# where a column data type might have changed
return utils.cast_to_num(value)
try:
value = float(value) # Convert string-based numbers to float
except ValueError:
return utils.cast_to_num(value)

if value == NULL_STRING:
return None
if value == EMPTY_STRING:
return ""
if target_generic_type == utils.GenericDataType.BOOLEAN:
return utils.cast_to_boolean(value)
return value

if target_generic_type == utils.GenericDataType.BOOLEAN:
return utils.cast_to_boolean(value)

return value


if isinstance(values, (list, tuple)):
values = [handle_single_value(v) for v in values] # type: ignore
Expand Down
Loading