FrancescoCastaldi commented on code in PR #45822:
URL: https://github.com/apache/superset/pull/45822#discussion_r4418259374
##########
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:
In commit `e74e08b55c`, we addressed this by updating
`tests/unit_tests/models/helpers_test.py`:
1. Corrected `QueryObject(..., filters=[...])` using the `filters=`
parameter so filters are preserved rather than swallowed by `**kwargs`.
2. In `test_processing_time_offsets`, structured the test with a valid outer
time range and non-datetime index series alongside a malformed second temporal
filter (`col="other_ds", val="a : b"`) and relative offset (`"1 day ago"`),
verifying that `QueryObjectValidationError` names `other_ds` and chains
`TimeRangeParseFailError` on `__cause__`.
3. Added a dedicated test for the `DATE_RANGE_TIMESHIFTS_ENABLED` code path
with an invalid date range offset (`"2024-02-01 : 2024-01-01"`), asserting
`QueryObjectValidationError` chains the underlying parse failure.
4. Added test assertions verifying that `table.get_sqla_query` also chains
the underlying parse exception on `__cause__`.
5. In `superset/models/helpers.py`, formatted the validation exception
string directly without `_()`, resolving the translation template drift flagged
by `scripts/translations/check_pot_drift.py` and `babel-extract`, while
strictly adhering to the 88-column limit.
--
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]