codeant-ai-for-open-source[bot] commented on code in PR #41975:
URL: https://github.com/apache/superset/pull/41975#discussion_r3584263803
##########
superset/db_engine_specs/bigquery.py:
##########
@@ -728,15 +728,17 @@ def _get_client(
"Could not import libraries needed to connect to BigQuery."
)
+ project: str | None = engine.url.host or engine.url.database or None
Review Comment:
**Suggestion:** The new project resolution incorrectly falls back to
`engine.url.database`, but for BigQuery that field can represent the default
dataset (schema), not a project. When a connection has no catalog/project (for
example `bigquery://`) and a schema is supplied, this will pass the dataset
name as the client project and cause metadata calls to resolve against the
wrong project (often producing dataset-not-found errors). Derive the client
project only from the actual catalog/project component, and do not treat
dataset/schema as a project fallback. [incorrect variable usage]
<details>
<summary><b>Severity Level:</b> Major ⚠️</summary>
```mdx
- ❌ Time partition metadata fails for ADC-only BigQuery connections.
- ❌ Query cost estimation errors for hostless BigQuery URIs.
- ⚠️ Catalog discovery may misidentify dataset as project name.
```
</details>
<details>
<summary><b>Steps of Reproduction ✅ </b></summary>
```mdx
1. Configure a Superset BigQuery database with SQLAlchemy URI `bigquery://`
(no project or
dataset), so `Database.sqlalchemy_uri_decrypted` has an empty `host` and
`database` as
used by `_get_sqla_engine` in `superset/models/core.py:520-59`.
2. Run a metadata operation on a table referenced only by dataset and table
(for example
`my_dataset.my_table`), producing a `Table` object with `catalog=None` and
`schema="my_dataset"` that is passed into
`BigQueryEngineSpec.get_extra_table_metadata()`
and `get_time_partition_column()` in
`superset/db_engine_specs/bigquery.py:596-34`.
3. Inside `get_time_partition_column()` at
`superset/db_engine_specs/bigquery.py:602-26`,
Superset obtains an engine via `cls.get_engine(database,
catalog=table.catalog,
schema=table.schema)`, which calls `Database._get_sqla_engine()`; this in
turn invokes
`BigQueryEngineSpec.adjust_engine_params()` at
`superset/db_engine_specs/bigquery.py:832-23`, setting `uri.database` to the
schema
(`"my_dataset"`) while leaving `uri.host` empty because neither the URI nor
the `catalog`
argument supplies a project.
4. `_get_client()` at `superset/db_engine_specs/bigquery.py:718-46` then
computes
`project: str | None = engine.url.host or engine.url.database or None` (line
731); with
`engine.url.host` empty and `engine.url.database="my_dataset"`, it passes
`project="my_dataset"` into `bigquery.Client(credentials=credentials,
project=project)` at
`bigquery.py:738-42`, causing subsequent calls like
`client.get_table(table_ref)` in
`get_time_partition_column()` at `bigquery.py:605-30` to resolve against the
incorrect
project and raise dataset-not-found errors when the dataset actually resides
in the ADC
project.
```
</details>
[](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt_id=38fc1d15df604bfa9d06a6205bc9df21&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
[](https://app.codeant.ai/fix-in-ide?tool=vscode-claude&prompt_id=38fc1d15df604bfa9d06a6205bc9df21&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:**
*Incorrect Variable Usage: The new project resolution incorrectly falls
back to `engine.url.database`, but for BigQuery that field can represent the
default dataset (schema), not a project. When a connection has no
catalog/project (for example `bigquery://`) and a schema is supplied, this will
pass the dataset name as the client project and cause metadata calls to resolve
against the wrong project (often producing dataset-not-found errors). Derive
the client project only from the actual catalog/project component, and do not
treat dataset/schema as a project fallback.
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=94f127d857566d7822bcf98c42c23fd1cb8ac14f4751a433b767945eeeed48e5&reaction=like'>👍</a>
| <a
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F41975&comment_hash=94f127d857566d7822bcf98c42c23fd1cb8ac14f4751a433b767945eeeed48e5&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]