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


##########
tests/unit_tests/db_engine_specs/test_bigquery.py:
##########
@@ -430,6 +430,52 @@ def test_get_default_catalog(mocker: MockerFixture) -> 
None:
     assert BigQueryEngineSpec.get_default_catalog(database) == "project"
 
 
+def test_get_client_uses_uri_project_with_service_account_credentials(
+    mocker: MockerFixture,
+) -> None:
+    """Test that service-account clients use the project from the engine 
URI."""
+    from superset.db_engine_specs.bigquery import BigQueryEngineSpec
+
+    credentials_info = {"project_id": "credential-project"}
+    credentials = mock.Mock()
+    engine = mock.MagicMock()
+    engine.url = make_url("bigquery://uri-project")
+    engine.dialect.credentials_info = credentials_info
+    create_credentials = mocker.patch(
+        "superset.db_engine_specs.bigquery.service_account.Credentials."
+        "from_service_account_info",
+        return_value=credentials,
+    )
+    client = mocker.patch("superset.db_engine_specs.bigquery.bigquery.Client")

Review Comment:
   **Suggestion:** Add explicit type annotations for newly introduced local 
variables in this test to satisfy the type-hint requirement. [custom_rule]
   
   **Severity Level:** Minor ๐Ÿงน
   <details>
   <summary><b>Why it matters? โญ </b></summary>
   
   The added test introduces several local variables without type annotations, 
including mock objects and the credentials_info dict. This matches the 
type-hint rule for newly added Python code, so the suggestion is a real 
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=cbde7a5b60a34eadac92179ee783db71&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=cbde7a5b60a34eadac92179ee783db71&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/db_engine_specs/test_bigquery.py
   **Line:** 439:449
   **Comment:**
        *Custom Rule: Add explicit type annotations for newly introduced local 
variables in this test 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%2F41975&comment_hash=a6b2afb9ab7983a46ff860a66dc6db63460d893cb373261cf3c8c6204c4af08b&reaction=like'>๐Ÿ‘</a>
 | <a 
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F41975&comment_hash=a6b2afb9ab7983a46ff860a66dc6db63460d893cb373261cf3c8c6204c4af08b&reaction=dislike'>๐Ÿ‘Ž</a>



##########
tests/unit_tests/db_engine_specs/test_bigquery.py:
##########
@@ -430,6 +430,52 @@ def test_get_default_catalog(mocker: MockerFixture) -> 
None:
     assert BigQueryEngineSpec.get_default_catalog(database) == "project"
 
 
+def test_get_client_uses_uri_project_with_service_account_credentials(
+    mocker: MockerFixture,
+) -> None:
+    """Test that service-account clients use the project from the engine 
URI."""
+    from superset.db_engine_specs.bigquery import BigQueryEngineSpec
+
+    credentials_info = {"project_id": "credential-project"}
+    credentials = mock.Mock()
+    engine = mock.MagicMock()
+    engine.url = make_url("bigquery://uri-project")
+    engine.dialect.credentials_info = credentials_info
+    create_credentials = mocker.patch(
+        "superset.db_engine_specs.bigquery.service_account.Credentials."
+        "from_service_account_info",
+        return_value=credentials,
+    )
+    client = mocker.patch("superset.db_engine_specs.bigquery.bigquery.Client")
+
+    BigQueryEngineSpec._get_client(engine, mock.Mock())
+
+    create_credentials.assert_called_once_with(credentials_info)
+    client.assert_called_once_with(credentials=credentials, 
project="uri-project")
+
+
+def test_get_client_uses_uri_project_with_application_default_credentials(
+    mocker: MockerFixture,
+) -> None:
+    """Test that ADC clients use the project from the engine URI."""
+    from superset.db_engine_specs.bigquery import BigQueryEngineSpec
+
+    credentials = mock.Mock()
+    engine = mock.MagicMock()
+    engine.url = make_url("bigquery://uri-project")
+    engine.dialect.credentials_info = None
+    get_default_credentials = mocker.patch(
+        "superset.db_engine_specs.bigquery.google.auth.default",
+        return_value=(credentials, "credential-project"),
+    )
+    client = mocker.patch("superset.db_engine_specs.bigquery.bigquery.Client")

Review Comment:
   **Suggestion:** Add explicit type annotations for the new local variables in 
this test, including mocked objects and patched call handles. [custom_rule]
   
   **Severity Level:** Minor ๐Ÿงน
   <details>
   <summary><b>Why it matters? โญ </b></summary>
   
   The new test block assigns mock and patched objects to local variables 
without type hints. That is a direct match for the Python type-hint rule on 
newly introduced code.
   </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=06cf6c0f99cc405c971448f9bb00d548&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=06cf6c0f99cc405c971448f9bb00d548&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/db_engine_specs/test_bigquery.py
   **Line:** 463:471
   **Comment:**
        *Custom Rule: Add explicit type annotations for the new local variables 
in this test, including mocked objects and patched call handles.
   
   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%2F41975&comment_hash=abc0c4aaeed2254ff69fddd08abef03effbd8cc500cadc7be328fee0cb6c790d&reaction=like'>๐Ÿ‘</a>
 | <a 
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F41975&comment_hash=abc0c4aaeed2254ff69fddd08abef03effbd8cc500cadc7be328fee0cb6c790d&reaction=dislike'>๐Ÿ‘Ž</a>



##########
superset/db_engine_specs/bigquery.py:
##########
@@ -728,15 +728,17 @@ def _get_client(
                 "Could not import libraries needed to connect to BigQuery."
             )
 
+        project = engine.url.host or None

Review Comment:
   **Suggestion:** Add an explicit type annotation for the new local `project` 
variable to satisfy the type-hint requirement. [custom_rule]
   
   **Severity Level:** Minor ๐Ÿงน
   <details>
   <summary><b>Why it matters? โญ </b></summary>
   
   The new local variable `project` is clearly type-annotatable as `str | 
None`, but it is introduced without a type hint. This matches the custom rule 
requiring type hints on new or modified Python variables that can be annotated.
   </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=c262277d17b440d9b0f9e2e4d4619f9e&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=c262277d17b440d9b0f9e2e4d4619f9e&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:** superset/db_engine_specs/bigquery.py
   **Line:** 731:731
   **Comment:**
        *Custom Rule: Add an explicit type annotation for the new local 
`project` 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%2F41975&comment_hash=6a1b851978deee96445ed45cee87e2743548bef5f1e9a05907270e2c59439bd2&reaction=like'>๐Ÿ‘</a>
 | <a 
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F41975&comment_hash=6a1b851978deee96445ed45cee87e2743548bef5f1e9a05907270e2c59439bd2&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