dabla commented on PR #38715:
URL: https://github.com/apache/airflow/pull/38715#issuecomment-2044256555

   I saw when addapting the hooks depending on the DbApiHook that some methods 
like in the MySqlHook open connections and cursors without a context manager or 
try/except block which is dangerous as when something goes wrong the connection 
and/or cursor won't be closed.
   
   For example:
   ```
       def bulk_load_custom(
           self, table: str, tmp_file: str, duplicate_key_handling: str = 
"IGNORE", extra_options: str = ""
       ) -> None:
           conn = self.get_conn()
           cursor = conn.cursor()
   
           cursor.execute(
               f"LOAD DATA LOCAL INFILE %s %s INTO TABLE {table} %s",
               (tmp_file, duplicate_key_handling, extra_options),
           )
   
           cursor.close()
           conn.commit()
           conn.close()  # type: ignore[misc]
   ```
   
   I think I will open a new PR for this and review all those once this PR is 
done and refactor it using the closing context manager from contextlib so that 
we are safe on that side.


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

Reply via email to