You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@superset.apache.org by el...@apache.org on 2026/10/14 22:01:36 UTC
(superset) branch master updated: fix(explore): raise a validation error instead of asserting when an IN filter has no value (SC-124271) (#44986)
This is an automated email from the ASF dual-hosted git repository.
eschutho pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/superset.git
The following commit(s) were added to refs/heads/master by this push:
new fa0999745fb fix(explore): raise a validation error instead of asserting when an IN filter has no value (SC-124271) (#44986)
fa0999745fb is described below
commit fa0999745fb552117eb44872fb9e466632611b9a
Author: Elizabeth Thompson <es...@gmail.com>
AuthorDate: Wed Oct 14 15:01:26 2026 -0700
fix(explore): raise a validation error instead of asserting when an IN filter has no value (SC-124271) (#44986)
Co-authored-by: Claude Sonnet 5.5 <no...@anthropic.com>
---
superset/models/helpers.py | 18 +++++
superset/translations/messages.pot | 4 +
tests/unit_tests/models/helpers_test.py | 132 ++++++++++++++++++++++++++++++++
3 files changed, 154 insertions(+)
diff --git a/superset/models/helpers.py b/superset/models/helpers.py
index c74825c706c..77a18702172 100644
--- a/superset/models/helpers.py
+++ b/superset/models/helpers.py
@@ -5366,6 +5366,22 @@ class ExploreMixin: # pylint: disable=too-many-public-methods
db_engine_spec=db_engine_spec,
db_extra=self.db_extra,
)
+ if op in {
+ utils.FilterOperator.IN,
+ utils.FilterOperator.NOT_IN,
+ } and not isinstance(eq, (tuple, list)):
+ # A missing or null value (``val`` absent or ``None``)
+ # leaves ``eq`` as ``None``. Reject it before any branch
+ # (advanced data types, array columns, plain IN) uses it,
+ # rather than dropping the filter, which would widen the
+ # results.
+ raise QueryObjectValidationError(
+ _(
+ "Filter value is required for the IN / NOT IN "
+ "operator on column %(column)s",
+ column=get_column_name(flt_col),
+ )
+ )
# Get ADVANCED_DATA_TYPES from config when needed
ADVANCED_DATA_TYPES = app.config.get("ADVANCED_DATA_TYPES", {}) # noqa: N806
@@ -5446,6 +5462,8 @@ class ExploreMixin: # pylint: disable=too-many-public-methods
# CONTAINS_ANY/CONTAINS_ALL also produce a list ``eq`` (they
# are in ``is_list_target``), but are element-level array ops
# handled by their own branch below — not IN.
+ # Non-list values were rejected right after
+ # ``filter_values_handler`` above.
assert isinstance(eq, (tuple, list))
if len(eq) == 0:
raise QueryObjectValidationError(
diff --git a/superset/translations/messages.pot b/superset/translations/messages.pot
index 3d2c4aaa9ab..c77ac8b2070 100644
--- a/superset/translations/messages.pot
+++ b/superset/translations/messages.pot
@@ -6824,6 +6824,10 @@ msgstr ""
msgid "Filter value is required"
msgstr ""
+#, python-format
+msgid "Filter value is required for the IN / NOT IN operator on column %(column)s"
+msgstr ""
+
msgid "Filter value list cannot be empty"
msgstr ""
diff --git a/tests/unit_tests/models/helpers_test.py b/tests/unit_tests/models/helpers_test.py
index 12b5a3e2048..7346969e1ce 100644
--- a/tests/unit_tests/models/helpers_test.py
+++ b/tests/unit_tests/models/helpers_test.py
@@ -3108,6 +3108,138 @@ def test_get_sqla_query_in_filter_preserves_float_precision_with_null(
)
+@pytest.mark.parametrize(
+ "flt",
+ [
+ pytest.param({"col": "region", "op": "IN"}, id="in-missing-val"),
+ pytest.param({"col": "region", "op": "NOT IN"}, id="not-in-missing-val"),
+ pytest.param({"col": "region", "op": "IN", "val": None}, id="in-val-none"),
+ pytest.param(
+ {"col": "region", "op": "NOT IN", "val": None}, id="not-in-val-none"
+ ),
+ ],
+)
+def test_get_sqla_query_in_filter_without_value_raises_validation_error(
+ database: Database,
+ flt: dict[str, Any],
+) -> None:
+ """
+ An IN / NOT IN filter with no value must raise a QueryObjectValidationError
+ (surfaced to the client as a 4xx) rather than an AssertionError (a 500).
+ The filter must not be silently dropped, as that would widen the results.
+ """
+ from superset.connectors.sqla.models import SqlaTable, TableColumn
+ from superset.exceptions import QueryObjectValidationError
+
+ table = SqlaTable(
+ database=database,
+ schema=None,
+ table_name="t",
+ columns=[
+ TableColumn(column_name="region", type="VARCHAR(255)"),
+ TableColumn(column_name="created_at", type="TIMESTAMP", is_dttm=True),
+ ],
+ )
+
+ with pytest.raises(QueryObjectValidationError, match="region"):
+ table.get_sqla_query(
+ columns=["region"],
+ filter=[
+ {"col": "created_at", "op": "TEMPORAL_RANGE", "val": "No filter"},
+ flt, # type: ignore[list-item]
+ ],
+ extras={},
+ is_timeseries=False,
+ metrics=[],
+ )
+
+
+@pytest.mark.parametrize(
+ "flt",
+ [
+ pytest.param({"col": "ip", "op": "IN"}, id="in-missing-val"),
+ pytest.param({"col": "ip", "op": "NOT IN"}, id="not-in-missing-val"),
+ pytest.param({"col": "ip", "op": "IN", "val": None}, id="in-val-none"),
+ pytest.param({"col": "ip", "op": "NOT IN", "val": None}, id="not-in-val-none"),
+ ],
+)
+def test_get_sqla_query_in_filter_without_value_advanced_data_type(
+ mocker: MockerFixture,
+ database: Database,
+ flt: dict[str, Any],
+) -> None:
+ """
+ With ENABLE_ADVANCED_DATA_TYPES on, an IN / NOT IN filter with no value on an
+ advanced-data-type column must raise a QueryObjectValidationError rather than
+ passing ``None`` to ``translate_type`` (a TypeError, i.e. a 500).
+ """
+ from superset.connectors.sqla.models import SqlaTable, TableColumn
+ from superset.exceptions import QueryObjectValidationError
+
+ mocker.patch(
+ "superset.models.helpers.feature_flag_manager.is_feature_enabled",
+ side_effect=lambda feature: feature == "ENABLE_ADVANCED_DATA_TYPES",
+ )
+
+ table = SqlaTable(
+ database=database,
+ schema=None,
+ table_name="t",
+ columns=[
+ TableColumn(
+ column_name="ip",
+ type="VARCHAR(255)",
+ advanced_data_type="internet_address",
+ ),
+ ],
+ )
+
+ with pytest.raises(QueryObjectValidationError, match="ip"):
+ table.get_sqla_query(
+ columns=["ip"],
+ filter=[flt], # type: ignore[list-item]
+ extras={},
+ is_timeseries=False,
+ metrics=[],
+ )
+
+
+@pytest.mark.parametrize("op", ["IN", "NOT IN"])
+def test_get_sqla_query_in_filter_with_value_builds_query(
+ database: Database,
+ op: str,
+) -> None:
+ """
+ A valid IN / NOT IN filter keeps building the expected IN clause.
+ """
+ from superset.connectors.sqla.models import SqlaTable, TableColumn
+
+ table = SqlaTable(
+ database=database,
+ schema=None,
+ table_name="t",
+ columns=[TableColumn(column_name="region", type="VARCHAR(255)")],
+ )
+
+ sqla_query = table.get_sqla_query(
+ columns=["region"],
+ filter=[{"col": "region", "op": op, "val": ["EMEA", "APAC"]}],
+ extras={},
+ is_timeseries=False,
+ metrics=[],
+ )
+
+ with database.get_sqla_engine() as engine:
+ sql = str(
+ sqla_query.sqla_query.compile(
+ dialect=engine.dialect,
+ compile_kwargs={"literal_binds": True},
+ )
+ )
+
+ assert f"region {op} ('EMEA', 'APAC')" in sql
+
+
def test_multiple_calculated_columns_each_parenthesized(
database: Database,
) -> None: