bito-code-review[bot] commented on PR #43309:
URL: https://github.com/apache/superset/pull/43309#issuecomment-5340063533

   <!-- Bito Reply -->
   The flagged issue is correct. The current implementation of 
`_get_validation_connections` eagerly calls `.connect()` for all subjects, 
which can trigger an `invalid_grant` error if the service account lacks 
domain-wide delegation, preventing successful validation even if the 
service-account-only connection would have worked.
   
   To resolve this, you should modify `_get_validation_connections` to return a 
list of callables (or a generator) that create and connect the engines lazily, 
rather than returning a list of already-connected `Connection` objects. Then, 
update the validation loop to call these factories only when needed and handle 
potential connection errors gracefully.
   
   Would you like me to fetch all other comments on this PR to validate them 
and implement a comprehensive fix?
   
   **superset/db_engine_specs/gsheets.py**
   ```
   @classmethod
       def _get_validation_connections(cls, encrypted_credentials: dict[str, 
Any]) -> list[Callable[[], Connection]]:
           subjects: list[str | None] = [None]
           if g.user and g.user.email:
               subjects.append(g.user.email)
   
           return [
               lambda s=subject: create_engine(
                   "gsheets://",
                   connect_args={"adapter_kwargs": {"gsheetsapi": 
{"service_account_info": encrypted_credentials, "subject": s}}},
                   future=True,
               ).connect()
               for subject in subjects
           ]
   ```


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