codeant-ai-for-open-source[bot] commented on code in PR #41960:
URL: https://github.com/apache/superset/pull/41960#discussion_r3578560022


##########
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:
   **Suggestion:** Add an explicit type annotation to this local variable so 
the constructed query object is typed. [custom_rule]
   
   **Severity Level:** Minor ๐Ÿงน
   <details>
   <summary><b>Why it matters? โญ </b></summary>
   
   This is a new local variable whose type is clearly inferable as QueryObject, 
so it falls under the rule requiring type hints for relevant annotatable 
variables.
   </details>
   <details>
   <summary><b>Rule source ๐Ÿ“– </b></summary>
   
   .cursor/rules/dev-standard.mdc (line 28)
   </details>
   
   [![Fix in 
Cursor](https://new-codeant-butcket.s3.us-west-1.amazonaws.com/badges/fix-in-cursor-flat.svg)](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt_id=cffea2cc67b946a7b335f708f15e79b9&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
 [![Fix in VSCode 
Claude](https://new-codeant-butcket.s3.us-west-1.amazonaws.com/badges/fix-in-vscode-claude-flat.svg)](https://app.codeant.ai/fix-in-ide?tool=vscode-claude&prompt_id=cffea2cc67b946a7b335f708f15e79b9&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
   
   *(Use Cmd/Ctrl + Click for best experience)*
   <details>
   <summary><b>Prompt for AI Agent ๐Ÿค– </b></summary>
   
   ```mdx
   This is a comment left during a code review.
   
   **Path:** tests/unit_tests/common/test_query_actions.py
   **Line:** 56:60
   **Comment:**
        *Custom Rule: Add an explicit type annotation to this local variable so 
the constructed query object is typed.
   
   Validate the correctness of the flagged issue. If correct, How can I resolve 
this? If you propose a fix, implement it and please make it concise.
   Once fix is implemented, also check other comments on the same PR, and ask 
user if the user wants to fix the rest of the comments as well. if said yes, 
then fetch all the comments validate the correctness and implement a minimal fix
   ```
   </details>
   <a 
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F41960&comment_hash=35c5944dacec29436a037dcba363b95152e8f1d16de4705a4a9b44e8f4593c32&reaction=like'>๐Ÿ‘</a>
 | <a 
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F41960&comment_hash=35c5944dacec29436a037dcba363b95152e8f1d16de4705a4a9b44e8f4593c32&reaction=dislike'>๐Ÿ‘Ž</a>



##########
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:
   **Suggestion:** Add a type hint for this local variable to keep the test 
context object explicitly typed. [custom_rule]
   
   **Severity Level:** Minor ๐Ÿงน
   <details>
   <summary><b>Why it matters? โญ </b></summary>
   
   This is a newly added local variable and its intended role is explicit in 
the test, so it can be annotated; omitting a type hint matches the custom rule 
violation.
   </details>
   <details>
   <summary><b>Rule source ๐Ÿ“– </b></summary>
   
   .cursor/rules/dev-standard.mdc (line 28)
   </details>
   
   [![Fix in 
Cursor](https://new-codeant-butcket.s3.us-west-1.amazonaws.com/badges/fix-in-cursor-flat.svg)](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt_id=8d38f11d817145acadd762b6c4d460cd&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
 [![Fix in VSCode 
Claude](https://new-codeant-butcket.s3.us-west-1.amazonaws.com/badges/fix-in-vscode-claude-flat.svg)](https://app.codeant.ai/fix-in-ide?tool=vscode-claude&prompt_id=8d38f11d817145acadd762b6c4d460cd&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
   
   *(Use Cmd/Ctrl + Click for best experience)*
   <details>
   <summary><b>Prompt for AI Agent ๐Ÿค– </b></summary>
   
   ```mdx
   This is a comment left during a code review.
   
   **Path:** tests/unit_tests/common/test_query_actions.py
   **Line:** 70:70
   **Comment:**
        *Custom Rule: Add a type hint for this local variable to keep the test 
context object explicitly typed.
   
   Validate the correctness of the flagged issue. If correct, How can I resolve 
this? If you propose a fix, implement it and please make it concise.
   Once fix is implemented, also check other comments on the same PR, and ask 
user if the user wants to fix the rest of the comments as well. if said yes, 
then fetch all the comments validate the correctness and implement a minimal fix
   ```
   </details>
   <a 
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F41960&comment_hash=fd815bd5db8f0b545d34c6fbf6df2989f57875c4211c482e7b15ed0fa42901f7&reaction=like'>๐Ÿ‘</a>
 | <a 
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F41960&comment_hash=fd815bd5db8f0b545d34c6fbf6df2989f57875c4211c482e7b15ed0fa42901f7&reaction=dislike'>๐Ÿ‘Ž</a>



##########
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:
   **Suggestion:** Add a concrete type annotation for this extracted result 
variable to satisfy the type-hint requirement. [custom_rule]
   
   **Severity Level:** Minor ๐Ÿงน
   <details>
   <summary><b>Why it matters? โญ </b></summary>
   
   This is a new local variable whose value is drawn from a typed container, 
and it can be annotated as QueryObject; the omission of a type hint is a real 
instance of the rule.
   </details>
   <details>
   <summary><b>Rule source ๐Ÿ“– </b></summary>
   
   .cursor/rules/dev-standard.mdc (line 28)
   </details>
   
   [![Fix in 
Cursor](https://new-codeant-butcket.s3.us-west-1.amazonaws.com/badges/fix-in-cursor-flat.svg)](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt_id=9604fc0a50a64b219ed0d663ed4ead60&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
 [![Fix in VSCode 
Claude](https://new-codeant-butcket.s3.us-west-1.amazonaws.com/badges/fix-in-vscode-claude-flat.svg)](https://app.codeant.ai/fix-in-ide?tool=vscode-claude&prompt_id=9604fc0a50a64b219ed0d663ed4ead60&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
   
   *(Use Cmd/Ctrl + Click for best experience)*
   <details>
   <summary><b>Prompt for AI Agent ๐Ÿค– </b></summary>
   
   ```mdx
   This is a comment left during a code review.
   
   **Path:** tests/unit_tests/common/test_query_actions.py
   **Line:** 84:84
   **Comment:**
        *Custom Rule: Add a concrete type annotation for this extracted result 
variable to satisfy the type-hint requirement.
   
   Validate the correctness of the flagged issue. If correct, How can I resolve 
this? If you propose a fix, implement it and please make it concise.
   Once fix is implemented, also check other comments on the same PR, and ask 
user if the user wants to fix the rest of the comments as well. if said yes, 
then fetch all the comments validate the correctness and implement a minimal fix
   ```
   </details>
   <a 
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F41960&comment_hash=8a9c4940c5a9265d7e4d811e05db05cce0c114918966ed527711a98f15aefb36&reaction=like'>๐Ÿ‘</a>
 | <a 
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F41960&comment_hash=8a9c4940c5a9265d7e4d811e05db05cce0c114918966ed527711a98f15aefb36&reaction=dislike'>๐Ÿ‘Ž</a>



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