sadpandajoe commented on code in PR #45822:
URL: https://github.com/apache/superset/pull/45822#discussion_r4403772285
##########
tests/unit_tests/models/helpers_test.py:
##########
@@ -6821,3 +6821,104 @@ def compile_not_in() -> str:
kql = compile_not_in()
assert "isnull(state)" in kql
assert "IS NULL" not in kql
+
+
+def test_get_sqla_query_malformed_temporal_range_raises_validation_error(
+ database: Database,
+) -> None:
+ """
+ Test that an invalid temporal range filter (e.g. 'a : b' or inverted dates)
+ raises QueryObjectValidationError naming the column, returning 400 instead
of 500.
+ Fixes #45459.
+ """
+ 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="ds", type="TIMESTAMP", is_dttm=True),
+ TableColumn(column_name="other_ds", type="TIMESTAMP",
is_dttm=True),
+ ],
+ )
+
+ with pytest.raises(QueryObjectValidationError, match="other_ds"):
+ table.get_sqla_query(
+ columns=["ds"],
+ metrics=[],
+ extras={},
+ filter=[
+ {
+ "col": "ds",
+ "op": FilterOperator.TEMPORAL_RANGE,
+ "val": "2024-01-01 : 2024-01-02",
+ },
+ {
+ "col": "other_ds",
+ "op": FilterOperator.TEMPORAL_RANGE,
+ "val": "a : b",
+ },
+ ],
+ granularity=None,
+ is_timeseries=False,
+ )
+
+ with pytest.raises(QueryObjectValidationError, match="other_ds"):
+ table.get_sqla_query(
+ columns=["ds"],
+ metrics=[],
+ extras={},
+ filter=[
+ {
+ "col": "ds",
+ "op": FilterOperator.TEMPORAL_RANGE,
+ "val": "2024-01-01 : 2024-01-02",
+ },
+ {
+ "col": "other_ds",
+ "op": FilterOperator.TEMPORAL_RANGE,
+ "val": "2024-02-01 : 2024-01-01",
+ },
+ ],
+ granularity=None,
+ is_timeseries=False,
+ )
+
+
+def test_processing_time_offsets_malformed_time_range_raises_validation_error(
+ database: Database,
+) -> None:
+ """
+ Test that processing_time_offsets raises QueryObjectValidationError on
+ malformed temporal filters when calculating time shifts.
+ Fixes #45459.
+ """
+ import pandas as pd
+
+ from superset.common.query_object import QueryObject
+ 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="ds", type="TIMESTAMP", is_dttm=True),
+ ],
+ )
+
+ query_object = QueryObject(
+ columns=["ds"],
+ filter=[
Review Comment:
`QueryObject.__init__` takes `filters=`, not `filter=`; this keyword is
swallowed by `**kwargs`, so `query_object.filter` stays empty and no `a : b`
range is ever parsed. The test passes only because the empty outer range
already raises the existing "enclosed time range" `QueryObjectValidationError`,
so it would stay green with the new `except` blocks removed. The date-range
offset catch and the relative-offset filter-rewrite catch aren't reached by
either new test either. Could this test pass `filters=` with a valid x-axis
range plus a malformed second temporal filter (and one with
`DATE_RANGE_TIMESHIFTS_ENABLED` and an offset like `2024-01-01:2024-01-02`),
and assert the error names the column or chains `TimeRangeParseFailError`?
--
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]