Skip to content

fix(dashboard): filter numeric values correctly #33230

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 9 commits into
base: master
Choose a base branch
from
12 changes: 12 additions & 0 deletions superset/connectors/sqla/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -528,6 +528,13 @@ def filter_values_handler( # pylint: disable=too-many-arguments # noqa: C901
def handle_single_value(value: FilterValue | None) -> FilterValue | None:
if operator == utils.FilterOperator.TEMPORAL_RANGE:
return value

if (
isinstance(value, (float, int))
and target_generic_type == utils.GenericDataType.NUMERIC
):
value = float(value)

if (
isinstance(value, (float, int))
and target_generic_type == utils.GenericDataType.TEMPORAL
Expand All @@ -553,6 +560,11 @@ def handle_single_value(value: FilterValue | None) -> FilterValue | None:
):
# For backwards compatibility and edge cases
# where a column data type might have changed
try:
value = float(value)
except ValueError:
logger.error(f"Unable to cast value {value} to num")

return utils.cast_to_num(value)
if value == NULL_STRING:
return None
Expand Down