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


##########
tests/unit_tests/daos/test_base_relationship_filters.py:
##########
@@ -0,0 +1,203 @@
+# 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.
+
+"""Tests for BaseDAO.apply_column_operators with relationship columns.
+
+`apply_column_operators` historically only worked on scalar columns. When a
+caller asked for `{col: "<m2m_relationship>", opr: "eq", value: <id>}` the
+SQLAlchemy backend raised "Can't compare a collection to an object."
+
+The behavior now: detect the relationship attribute and dispatch to
+`column.any(<related_pk> == value)`, so callers can use the natural shape
+for both scalar columns and m2m relationships.
+"""
+
+from unittest.mock import MagicMock
+
+import pytest
+
+from superset.daos.base import BaseDAO, ColumnOperator, ColumnOperatorEnum
+from superset.models.slice import Slice
+
+
+class _SliceDAO(BaseDAO[Slice]):
+    """Tiny concrete DAO so we can exercise the BaseDAO logic against the
+    real Slice model + its m2m `dashboards` relationship without standing up
+    a full database."""
+
+    model_cls = Slice
+    filterable_relationships = frozenset({"dashboards"})
+
+
+class _SliceDAONoRelationships(BaseDAO[Slice]):
+    """Same model but with no relationships opted into discovery. Used to
+    verify the default behavior (empty ``filterable_relationships``)
+    keeps relationship columns out of the schema-discovery output."""
+
+    model_cls = Slice
+
+
+class TestApplyColumnOperatorsRelationship:
+    """`apply_column_operators` handles m2m relationship columns via .any()."""
+
+    def test_eq_on_relationship_dispatches_to_any(self):
+        """`{col: 'dashboards', opr: 'eq', value: 42}` calls .any() on the
+        relationship and compares the related model's PK to 42."""
+        mock_query = MagicMock()
+        mock_query.filter.return_value = mock_query
+
+        result = _SliceDAO.apply_column_operators(
+            mock_query,
+            [ColumnOperator(col="dashboards", opr=ColumnOperatorEnum.eq, 
value=42)],
+        )
+
+        assert result is mock_query
+        # We applied exactly one filter
+        assert mock_query.filter.call_count == 1
+        # And the argument is a SQLAlchemy BinaryExpression that survives
+        # being passed to .filter() — we can't easily inspect its structure
+        # without rendering SQL, but we can verify the dispatch happened
+        # without raising.
+
+    def test_eq_on_scalar_column_unchanged(self):
+        """Non-relationship columns continue using the old scalar path."""
+        mock_query = MagicMock()
+        mock_query.filter.return_value = mock_query
+
+        _SliceDAO.apply_column_operators(
+            mock_query,
+            [
+                ColumnOperator(
+                    col="slice_name", opr=ColumnOperatorEnum.eq, 
value="Revenue"
+                )
+            ],
+        )
+        assert mock_query.filter.call_count == 1
+
+    def test_invalid_column_still_raises(self):

Review Comment:
   **Suggestion:** Add an explicit return type annotation to this method (for 
example, `-> None`) to align with the rule requiring type hints on new Python 
methods. [custom_rule]
   
   **Severity Level:** Minor ⚠️
   <details>
   <summary><b>Why it matters? 🤔 </b></summary>
   
   This is another new test method without a return type annotation. That 
directly violates the requirement that newly added Python functions and methods 
be fully typed.
   </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=a52968a2df2e41be848f78bafa468445&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=a52968a2df2e41be848f78bafa468445&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/daos/test_base_relationship_filters.py
   **Line:** 91:91
   **Comment:**
        *Custom Rule: Add an explicit return type annotation to this method 
(for example, `-> None`) to align with the rule requiring type hints on new 
Python methods.
   
   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%2F40397&comment_hash=6672ff63e7e11181c490c8080a40e154866cefe34c92c3d6ac9a48ab8b16dd71&reaction=like'>👍</a>
 | <a 
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F40397&comment_hash=6672ff63e7e11181c490c8080a40e154866cefe34c92c3d6ac9a48ab8b16dd71&reaction=dislike'>👎</a>



##########
tests/unit_tests/daos/test_base_relationship_filters.py:
##########
@@ -0,0 +1,203 @@
+# 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.
+
+"""Tests for BaseDAO.apply_column_operators with relationship columns.
+
+`apply_column_operators` historically only worked on scalar columns. When a
+caller asked for `{col: "<m2m_relationship>", opr: "eq", value: <id>}` the
+SQLAlchemy backend raised "Can't compare a collection to an object."
+
+The behavior now: detect the relationship attribute and dispatch to
+`column.any(<related_pk> == value)`, so callers can use the natural shape
+for both scalar columns and m2m relationships.
+"""
+
+from unittest.mock import MagicMock
+
+import pytest
+
+from superset.daos.base import BaseDAO, ColumnOperator, ColumnOperatorEnum
+from superset.models.slice import Slice
+
+
+class _SliceDAO(BaseDAO[Slice]):
+    """Tiny concrete DAO so we can exercise the BaseDAO logic against the
+    real Slice model + its m2m `dashboards` relationship without standing up
+    a full database."""
+
+    model_cls = Slice
+    filterable_relationships = frozenset({"dashboards"})
+
+
+class _SliceDAONoRelationships(BaseDAO[Slice]):
+    """Same model but with no relationships opted into discovery. Used to
+    verify the default behavior (empty ``filterable_relationships``)
+    keeps relationship columns out of the schema-discovery output."""
+
+    model_cls = Slice
+
+
+class TestApplyColumnOperatorsRelationship:
+    """`apply_column_operators` handles m2m relationship columns via .any()."""
+
+    def test_eq_on_relationship_dispatches_to_any(self):
+        """`{col: 'dashboards', opr: 'eq', value: 42}` calls .any() on the
+        relationship and compares the related model's PK to 42."""
+        mock_query = MagicMock()
+        mock_query.filter.return_value = mock_query
+
+        result = _SliceDAO.apply_column_operators(
+            mock_query,
+            [ColumnOperator(col="dashboards", opr=ColumnOperatorEnum.eq, 
value=42)],
+        )
+
+        assert result is mock_query
+        # We applied exactly one filter
+        assert mock_query.filter.call_count == 1
+        # And the argument is a SQLAlchemy BinaryExpression that survives
+        # being passed to .filter() — we can't easily inspect its structure
+        # without rendering SQL, but we can verify the dispatch happened
+        # without raising.
+
+    def test_eq_on_scalar_column_unchanged(self):

Review Comment:
   **Suggestion:** Add an explicit return type annotation to this test method 
(for example, `-> None`) so the new function is fully typed. [custom_rule]
   
   **Severity Level:** Minor ⚠️
   <details>
   <summary><b>Why it matters? 🤔 </b></summary>
   
   This newly added test method has no return type annotation. Since the PR 
adds new Python code, the typing rule applies and the omission is a genuine 
violation.
   </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=e0fd2fdca228478d8300b5e3d3f036ae&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=e0fd2fdca228478d8300b5e3d3f036ae&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/daos/test_base_relationship_filters.py
   **Line:** 76:76
   **Comment:**
        *Custom Rule: Add an explicit return type annotation to this test 
method (for example, `-> None`) so the new function is fully 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%2F40397&comment_hash=5e1dce64ad8b5d2db7194a474c936e6ec4ca8f71852af1c546d511a1a1f61e10&reaction=like'>👍</a>
 | <a 
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F40397&comment_hash=5e1dce64ad8b5d2db7194a474c936e6ec4ca8f71852af1c546d511a1a1f61e10&reaction=dislike'>👎</a>



##########
tests/unit_tests/daos/test_base_relationship_filters.py:
##########
@@ -0,0 +1,203 @@
+# 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.
+
+"""Tests for BaseDAO.apply_column_operators with relationship columns.
+
+`apply_column_operators` historically only worked on scalar columns. When a
+caller asked for `{col: "<m2m_relationship>", opr: "eq", value: <id>}` the
+SQLAlchemy backend raised "Can't compare a collection to an object."
+
+The behavior now: detect the relationship attribute and dispatch to
+`column.any(<related_pk> == value)`, so callers can use the natural shape
+for both scalar columns and m2m relationships.
+"""
+
+from unittest.mock import MagicMock
+
+import pytest
+
+from superset.daos.base import BaseDAO, ColumnOperator, ColumnOperatorEnum
+from superset.models.slice import Slice
+
+
+class _SliceDAO(BaseDAO[Slice]):
+    """Tiny concrete DAO so we can exercise the BaseDAO logic against the
+    real Slice model + its m2m `dashboards` relationship without standing up
+    a full database."""
+
+    model_cls = Slice
+    filterable_relationships = frozenset({"dashboards"})
+
+
+class _SliceDAONoRelationships(BaseDAO[Slice]):
+    """Same model but with no relationships opted into discovery. Used to
+    verify the default behavior (empty ``filterable_relationships``)
+    keeps relationship columns out of the schema-discovery output."""
+
+    model_cls = Slice
+
+
+class TestApplyColumnOperatorsRelationship:
+    """`apply_column_operators` handles m2m relationship columns via .any()."""
+
+    def test_eq_on_relationship_dispatches_to_any(self):
+        """`{col: 'dashboards', opr: 'eq', value: 42}` calls .any() on the
+        relationship and compares the related model's PK to 42."""
+        mock_query = MagicMock()
+        mock_query.filter.return_value = mock_query
+
+        result = _SliceDAO.apply_column_operators(
+            mock_query,
+            [ColumnOperator(col="dashboards", opr=ColumnOperatorEnum.eq, 
value=42)],
+        )
+
+        assert result is mock_query
+        # We applied exactly one filter
+        assert mock_query.filter.call_count == 1
+        # And the argument is a SQLAlchemy BinaryExpression that survives
+        # being passed to .filter() — we can't easily inspect its structure
+        # without rendering SQL, but we can verify the dispatch happened
+        # without raising.
+
+    def test_eq_on_scalar_column_unchanged(self):
+        """Non-relationship columns continue using the old scalar path."""
+        mock_query = MagicMock()
+        mock_query.filter.return_value = mock_query
+
+        _SliceDAO.apply_column_operators(
+            mock_query,
+            [
+                ColumnOperator(
+                    col="slice_name", opr=ColumnOperatorEnum.eq, 
value="Revenue"
+                )
+            ],
+        )
+        assert mock_query.filter.call_count == 1
+
+    def test_invalid_column_still_raises(self):
+        """Columns that don't exist on the model raise ValueError as before."""
+        mock_query = MagicMock()
+        with pytest.raises(ValueError, match="does not exist on Slice"):
+            _SliceDAO.apply_column_operators(
+                mock_query,
+                [
+                    ColumnOperator(
+                        col="does_not_exist", opr=ColumnOperatorEnum.eq, 
value=1
+                    )
+                ],
+            )
+
+    @pytest.mark.parametrize(
+        "operator",
+        [
+            ColumnOperatorEnum.eq,
+            ColumnOperatorEnum.ne,
+            ColumnOperatorEnum.in_,
+            ColumnOperatorEnum.nin,
+            ColumnOperatorEnum.is_null,
+            ColumnOperatorEnum.is_not_null,
+        ],
+    )
+    def test_supported_relationship_operators_dispatch(self, operator):
+        """eq/ne/in/nin/is_null/is_not_null all dispatch to .any() variants."""
+        mock_query = MagicMock()
+        mock_query.filter.return_value = mock_query
+
+        _SliceDAO.apply_column_operators(
+            mock_query,
+            [ColumnOperator(col="dashboards", opr=operator, value=[1, 2])],
+        )
+        assert mock_query.filter.call_count == 1
+
+    @pytest.mark.parametrize(
+        "operator",
+        [
+            ColumnOperatorEnum.sw,
+            ColumnOperatorEnum.ew,
+            ColumnOperatorEnum.like,
+            ColumnOperatorEnum.ilike,
+            ColumnOperatorEnum.gt,
+            ColumnOperatorEnum.gte,
+            ColumnOperatorEnum.lt,
+            ColumnOperatorEnum.lte,
+        ],
+    )
+    def test_unsupported_relationship_operators_raise(self, operator):

Review Comment:
   **Suggestion:** Add type hints for the `operator` parameter and the method 
return value (for example, `-> None`) to meet the full typing requirement for 
new methods. [custom_rule]
   
   **Severity Level:** Minor ⚠️
   <details>
   <summary><b>Why it matters? 🤔 </b></summary>
   
   This newly added parameterized method is missing type hints for its argument 
and its return value. That matches the custom rule violation exactly.
   </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=0383082a96d347bf95a9915710c8bfa6&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=0383082a96d347bf95a9915710c8bfa6&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/daos/test_base_relationship_filters.py
   **Line:** 139:139
   **Comment:**
        *Custom Rule: Add type hints for the `operator` parameter and the 
method return value (for example, `-> None`) to meet the full typing 
requirement for new methods.
   
   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%2F40397&comment_hash=6620b036d9064805cbc7a00f0f8ccf6fc4a4259b65d56e5abf6ed23531f03153&reaction=like'>👍</a>
 | <a 
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F40397&comment_hash=6620b036d9064805cbc7a00f0f8ccf6fc4a4259b65d56e5abf6ed23531f03153&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