rusackas commented on code in PR #41960:
URL: https://github.com/apache/superset/pull/41960#discussion_r3580492789


##########
tests/unit_tests/common/test_query_actions.py:
##########
@@ -0,0 +1,88 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+from typing import Any
+from unittest.mock import MagicMock, patch
+
+from superset.common.chart_data import ChartDataResultType
+from superset.common.query_actions import _get_drill_detail
+from superset.common.query_object import QueryObject
+from superset.utils.core import QueryObjectFilterClause
+
+
+@patch("superset.common.query_actions._get_full")
+def test_get_drill_detail_does_not_strip_filters(
+    mock_get_full: MagicMock,
+) -> None:
+    """
+    Characterization test for ``_get_drill_detail`` 
(superset/common/query_actions.py),
+    the backend transform behind the "Drill to Detail by" samples query.
+
+    ``_get_drill_detail`` shallow-copies the incoming ``QueryObject`` and 
rewrites
+    ``is_timeseries``, ``metrics``, ``post_processing``, ``columns`` and 
``orderby``;
+    it never reads or reassigns ``QueryObject.filter``. This test pins that
+    behavior down: filters present on the ``QueryObject`` handed to
+    ``_get_drill_detail`` are still present, unmodified, on the object it 
hands off
+    to ``_get_full``.
+
+    This is deliberately narrow and does NOT reproduce or close #28562 ("Drill 
to
+    Detail by" ignoring a dashboard's applied filters) -- that report describes
+    filters missing from the query *before* it reaches this function, which 
points
+    at the payload assembled upstream of ``_get_drill_detail`` (dashboard 
native
+    filter propagation into the chart's form data / the drill payload built on 
the
+    frontend), not at this transform. If that assembly is ever changed to drop
+    filters before calling into this code path, this test would not catch it; 
it
+    only guards against a regression introduced inside ``_get_drill_detail`` 
itself.
+    """
+    applied_filter: QueryObjectFilterClause = {
+        "col": "region",
+        "op": "==",
+        "val": "USA",
+    }
+
+    query_obj = QueryObject(
+        columns=["region", "sales"],
+        metrics=["count"],
+        filters=[applied_filter],
+    )

Review Comment:
   Added an explicit `QueryObject` annotation on `query_obj`.



##########
tests/unit_tests/common/test_query_actions.py:
##########
@@ -0,0 +1,88 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+from typing import Any
+from unittest.mock import MagicMock, patch
+
+from superset.common.chart_data import ChartDataResultType
+from superset.common.query_actions import _get_drill_detail
+from superset.common.query_object import QueryObject
+from superset.utils.core import QueryObjectFilterClause
+
+
+@patch("superset.common.query_actions._get_full")
+def test_get_drill_detail_does_not_strip_filters(
+    mock_get_full: MagicMock,
+) -> None:
+    """
+    Characterization test for ``_get_drill_detail`` 
(superset/common/query_actions.py),
+    the backend transform behind the "Drill to Detail by" samples query.
+
+    ``_get_drill_detail`` shallow-copies the incoming ``QueryObject`` and 
rewrites
+    ``is_timeseries``, ``metrics``, ``post_processing``, ``columns`` and 
``orderby``;
+    it never reads or reassigns ``QueryObject.filter``. This test pins that
+    behavior down: filters present on the ``QueryObject`` handed to
+    ``_get_drill_detail`` are still present, unmodified, on the object it 
hands off
+    to ``_get_full``.
+
+    This is deliberately narrow and does NOT reproduce or close #28562 ("Drill 
to
+    Detail by" ignoring a dashboard's applied filters) -- that report describes
+    filters missing from the query *before* it reaches this function, which 
points
+    at the payload assembled upstream of ``_get_drill_detail`` (dashboard 
native
+    filter propagation into the chart's form data / the drill payload built on 
the
+    frontend), not at this transform. If that assembly is ever changed to drop
+    filters before calling into this code path, this test would not catch it; 
it
+    only guards against a regression introduced inside ``_get_drill_detail`` 
itself.
+    """
+    applied_filter: QueryObjectFilterClause = {
+        "col": "region",
+        "op": "==",
+        "val": "USA",
+    }
+
+    query_obj = QueryObject(
+        columns=["region", "sales"],
+        metrics=["count"],
+        filters=[applied_filter],
+    )
+
+    col_region = MagicMock()
+    col_region.column_name = "region"
+    col_sales = MagicMock()
+    col_sales.column_name = "sales"
+
+    datasource = MagicMock()
+    datasource.columns = [col_region, col_sales]
+
+    query_context = MagicMock()

Review Comment:
   Added an explicit `MagicMock` annotation on `query_context`.



##########
tests/unit_tests/common/test_query_actions.py:
##########
@@ -0,0 +1,88 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+from typing import Any
+from unittest.mock import MagicMock, patch
+
+from superset.common.chart_data import ChartDataResultType
+from superset.common.query_actions import _get_drill_detail
+from superset.common.query_object import QueryObject
+from superset.utils.core import QueryObjectFilterClause
+
+
+@patch("superset.common.query_actions._get_full")
+def test_get_drill_detail_does_not_strip_filters(
+    mock_get_full: MagicMock,
+) -> None:
+    """
+    Characterization test for ``_get_drill_detail`` 
(superset/common/query_actions.py),
+    the backend transform behind the "Drill to Detail by" samples query.
+
+    ``_get_drill_detail`` shallow-copies the incoming ``QueryObject`` and 
rewrites
+    ``is_timeseries``, ``metrics``, ``post_processing``, ``columns`` and 
``orderby``;
+    it never reads or reassigns ``QueryObject.filter``. This test pins that
+    behavior down: filters present on the ``QueryObject`` handed to
+    ``_get_drill_detail`` are still present, unmodified, on the object it 
hands off
+    to ``_get_full``.
+
+    This is deliberately narrow and does NOT reproduce or close #28562 ("Drill 
to
+    Detail by" ignoring a dashboard's applied filters) -- that report describes
+    filters missing from the query *before* it reaches this function, which 
points
+    at the payload assembled upstream of ``_get_drill_detail`` (dashboard 
native
+    filter propagation into the chart's form data / the drill payload built on 
the
+    frontend), not at this transform. If that assembly is ever changed to drop
+    filters before calling into this code path, this test would not catch it; 
it
+    only guards against a regression introduced inside ``_get_drill_detail`` 
itself.
+    """
+    applied_filter: QueryObjectFilterClause = {
+        "col": "region",
+        "op": "==",
+        "val": "USA",
+    }
+
+    query_obj = QueryObject(
+        columns=["region", "sales"],
+        metrics=["count"],
+        filters=[applied_filter],
+    )
+
+    col_region = MagicMock()
+    col_region.column_name = "region"
+    col_sales = MagicMock()
+    col_sales.column_name = "sales"
+
+    datasource = MagicMock()
+    datasource.columns = [col_region, col_sales]
+
+    query_context = MagicMock()
+    query_context.datasource = datasource
+    query_context.result_type = ChartDataResultType.DRILL_DETAIL
+
+    captured: dict[str, QueryObject] = {}
+
+    def _capture(_ctx: MagicMock, obj: QueryObject, _force: bool) -> dict[str, 
Any]:
+        captured["query_obj"] = obj
+        return {}
+
+    mock_get_full.side_effect = _capture
+
+    _get_drill_detail(query_context, query_obj)
+
+    executed = captured["query_obj"]

Review Comment:
   Added an explicit `QueryObject` annotation on `executed`.



-- 
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]

Reply via email to