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

   <!-- Bito Reply -->
   The flagged issue is correct. Using `contextlib.closing` only ensures 
`close()` is called on the object, but it does not trigger the `__enter__` 
method of the context manager returned by `get_raw_connection()`. This bypasses 
critical lifecycle logic such as user impersonation, OAuth2 setup, and SSH 
tunnel management.
   
   To resolve this, you should use the connection directly as a context 
manager. Here is the corrected implementation for 
`superset/commands/streaming_export/base.py`:
   
   ```python
               # Use get_raw_connection() as a context manager directly
               with merged_database.get_raw_connection(catalog=catalog, 
schema=schema) as conn:
                   cursor = conn.cursor()
                   try:
                       cursor.execute(sql)
                       columns = (
                           [desc[0] for desc in cursor.description]
                           if cursor.description
                           else []
                       )
   ```
   
   This ensures the connection's `__enter__` and `__exit__` methods are 
properly invoked, handling the required setup and cleanup.
   
   **superset/commands/streaming_export/base.py**
   ```
   # Use get_raw_connection() as a context manager directly
               with merged_database.get_raw_connection(catalog=catalog, 
schema=schema) as conn:
                   cursor = conn.cursor()
                   try:
                       cursor.execute(sql)
                       columns = (
                           [desc[0] for desc in cursor.description]
                           if cursor.description
                           else []
                       )
   ```


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