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


##########
tests/unit_tests/db_engine_specs/test_starrocks.py:
##########
@@ -224,8 +225,8 @@ def test_get_catalog_names(mocker: MockerFixture) -> None:
     # StarRocks returns rows with keys: ['Catalog', 'Type', 'Comment']
     mock_row_1 = mocker.MagicMock()
     mock_row_1.keys.return_value = ["Catalog", "Type", "Comment"]
-    mock_row_1.__getitem__ = (
-        lambda self, key: "default_catalog" if key == "Catalog" else None
+    mock_row_1.__getitem__ = lambda self, key: (

Review Comment:
   **Suggestion:** The test attempts to override `__getitem__` on a `MagicMock` 
instance with a function taking `(self, key)`, but special methods are resolved 
on the class and this instance attribute is ignored, so `row["Catalog"]` will 
not return the expected string and the assertion on catalog names may fail; 
using `__getitem__.side_effect` with a single `key` argument correctly controls 
subscription behavior. [logic error]
   
   <details>
   <summary><b>Severity Level:</b> Major ⚠️</summary>
   
   ```mdx
   - ❌ `test_get_catalog_names` fails in unit test suite.
   - ⚠️ StarRocks catalog-name extraction logic left unverified.
   ```
   </details>
   
   ```suggestion
       mock_row_1.__getitem__.side_effect = lambda key: (
   ```
   <details>
   <summary><b>Steps of Reproduction ✅ </b></summary>
   
   ```mdx
   1. Run the unit test `pytest
   tests/unit_tests/db_engine_specs/test_starrocks.py::test_get_catalog_names`.
   
   2. In `test_get_catalog_names` (around lines 226-237), three `MagicMock` 
rows are created;
   for `mock_row_1`, `__getitem__` is overridden via instance assignment:
   
      `mock_row_1.__getitem__ = lambda self, key: ("default_catalog" if key == 
"Catalog" else
      None)`.
   
   3. The test sets `inspector.bind.execute.return_value = [mock_row_1, 
mock_row_2,
   mock_row_3]` and then calls `StarRocksEngineSpec.get_catalog_names(database, 
inspector)`,
   implemented in `superset/db_engine_specs/starrocks.py:335-367`, which does
   `catalogs.add(row["Catalog"])` when `"Catalog" in row.keys()`.
   
   4. Because special method lookup (`row["Catalog"]`) uses the class-level
   `MagicMock.__getitem__` and ignores the instance attribute assigned in the 
test, each
   `row["Catalog"]` returns a new `MagicMock` instead of the intended string; 
the resulting
   `catalogs` is a set of `MagicMock` objects, so the assertion `assert 
catalogs ==
   {"default_catalog", "hive", "iceberg"}` in the test fails.
   ```
   </details>
   <details>
   <summary><b>Prompt for AI Agent 🤖 </b></summary>
   
   ```mdx
   This is a comment left during a code review.
   
   **Path:** tests/unit_tests/db_engine_specs/test_starrocks.py
   **Line:** 228:228
   **Comment:**
        *Logic Error: The test attempts to override `__getitem__` on a 
`MagicMock` instance with a function taking `(self, key)`, but special methods 
are resolved on the class and this instance attribute is ignored, so 
`row["Catalog"]` will not return the expected string and the assertion on 
catalog names may fail; using `__getitem__.side_effect` with a single `key` 
argument correctly controls subscription behavior.
   
   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.
   ```
   </details>
   <a 
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F37984&comment_hash=8e7b2192bb3e5d38de8b94703b9eec8d945822b7c6518058997fc5fc64a8a290&reaction=like'>👍</a>
 | <a 
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F37984&comment_hash=8e7b2192bb3e5d38de8b94703b9eec8d945822b7c6518058997fc5fc64a8a290&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