uranusjr commented on a change in pull request #14869:
URL: https://github.com/apache/airflow/pull/14869#discussion_r601690218



##########
File path: airflow/providers/mysql/hooks/mysql.py
##########
@@ -50,20 +56,36 @@ def __init__(self, *args, **kwargs) -> None:
         self.schema = kwargs.pop("schema", None)
         self.connection = kwargs.pop("connection", None)
 
-    def set_autocommit(self, conn: Connection, autocommit: bool) -> None:  # 
noqa: D403
-        """MySql connection sets autocommit in a different way."""
-        conn.autocommit(autocommit)
+    def set_autocommit(self, conn: MySQLConnectionTypes, autocommit: bool) -> 
None:
+        """
+        The MySQLdb (mysqlclient) client uses an `autocommit` method rather
+        than an `autocommit` property to set the autocommit setting
+
+        :param conn: connection to set autocommit setting
+        :type MySQLConnectionTypes: connection object.
+        :param autocommit: autocommit setting
+        :type bool: True to enable autocommit, False to disable autocommit
+        :rtype: None
+        """
+        if hasattr(conn.__class__, 'autocommit') and 
isinstance(conn.__class__.autocommit, property):
+            conn.autocommit = autocommit
+        else:
+            conn.autocommit(autocommit)

Review comment:
       Would this be simpler?
   
   ```suggestion
           if callable(conn.autocommit):
               conn.autocommit(autocommit)
           else:
               conn.autocommit = autocommit
   ```




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

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


Reply via email to