codeant-ai-for-open-source[bot] commented on code in PR #43309:
URL: https://github.com/apache/superset/pull/43309#discussion_r3811669240
##########
superset/db_engine_specs/gsheets.py:
##########
@@ -351,6 +351,56 @@ def parameters_json_schema(cls) -> Any:
spec.components.schema(cls.__name__, schema=cls.parameters_schema)
return spec.to_dict()["components"]["schemas"][cls.__name__]
+ @classmethod
+ def _get_validation_connections(
+ cls,
+ encrypted_credentials: dict[str, Any],
+ ) -> list[Connection]:
+ """
+ Build the connections used to validate spreadsheet URLs, in priority
order.
+
+ Passing a `subject` makes Google authenticate through domain-wide
delegation,
+ impersonating that user. Service accounts without domain-wide
delegation
+ configured — the common setup, where the spreadsheet is simply shared
with the
+ service account email — get back `invalid_grant`, so validation could
never
+ succeed for them. We validate as the service account itself first,
which is
+ also how the connection behaves at query time, and only fall back to
+ impersonating the current user so that domain-wide delegation keeps
working:
+ there, the admin is able to add sheets that only they have access to,
even if
+ later users are not able to access them.
+ """
+ subjects: list[str | None] = [None]
+ if g.user and g.user.email:
+ subjects.append(g.user.email)
+
+ return [
+ create_engine(
+ "gsheets://",
+ connect_args={
+ "adapter_kwargs": {
+ "gsheetsapi": {
+ "service_account_info": encrypted_credentials,
+ "subject": subject,
+ }
+ }
+ },
+ future=True,
+ ).connect()
+ for subject in subjects
+ ]
Review Comment:
**Suggestion:** The list comprehension eagerly calls `.connect()` for both
identities before any URL is tested. If the service account lacks domain-wide
delegation, creating the delegated connection can raise `invalid_grant`,
aborting validation before the service-account connection is used successfully.
Construct and connect the delegated engine only after a service-account read
has failed, and handle connection-creation failures as a failed candidate
rather than propagating them. [error handling]
<details>
<summary><b>Severity Level:</b> Critical 🚨</summary>
```mdx
- ❌ Common service-account validation still fails.
- ❌ Database creation modal rejects readable spreadsheets.
- ⚠️ Domain-wide delegation fallback cannot remain lazy.
```
</details>
[](https://docs.codeant.ai/cli/resolve-pr-comments-skill)
<details>
<summary><b>Prompt for AI Agent 🤖 </b></summary>
```mdx
This is a comment left during a code review.
**Path:** superset/db_engine_specs/gsheets.py
**Line:** 376:390
**Comment:**
*Error Handling: The list comprehension eagerly calls `.connect()` for
both identities before any URL is tested. If the service account lacks
domain-wide delegation, creating the delegated connection can raise
`invalid_grant`, aborting validation before the service-account connection is
used successfully. Construct and connect the delegated engine only after a
service-account read has failed, and handle connection-creation failures as a
failed candidate rather than propagating them.
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%2F43309&comment_hash=7dbbca7c9a6bbeebd7c92d1d7ad28409434bea7cac1986c4ffcee04c27bec81e&reaction=like'>👍</a>
| <a
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F43309&comment_hash=7dbbca7c9a6bbeebd7c92d1d7ad28409434bea7cac1986c4ffcee04c27bec81e&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]