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


##########
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:
   ✅ **Customized review instruction saved!**
   
   **Instruction:**
   > Do not flag eager SQLAlchemy .connect() calls as Google authentication 
failures; GSheets credentials are authenticated when the spreadsheet query 
runs, and _can_read_url already handles those query failures as failed 
candidates.
   
   **Applied to:**
     - `superset/db_engine_specs/gsheets.py`
   
   ---
   💡 *To manage or update this instruction, visit: [CodeAnt AI 
Settings](https://app.codeant.ai/org/settings/learnings)*



-- 
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