You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by GitBox <gi...@apache.org> on 2021/03/18 16:33:48 UTC
[GitHub] [airflow] ericpp commented on a change in pull request #14869: Fixed autocommit calls for mysql-connector-python
ericpp commented on a change in pull request #14869:
URL: https://github.com/apache/airflow/pull/14869#discussion_r597049286
##########
File path: airflow/providers/mysql/hooks/mysql.py
##########
@@ -52,7 +52,10 @@ def __init__(self, *args, **kwargs) -> None:
def set_autocommit(self, conn: Connection, autocommit: bool) -> None: # noqa: D403
"""MySql connection sets autocommit in a different way."""
- conn.autocommit(autocommit)
+ if hasattr(conn, 'get_autocommit'): # mysqlclient
+ conn.autocommit(autocommit)
+ else: # mysql-connector-python
+ conn.autocommit = autocommit
Review comment:
I avoided doing that because `conn.autocommit` is actually a method with a property decorator around it. It has a side effect of running a `SELECT @@session.autocommit` query whenever you try to access it: https://github.com/mysql/mysql-connector-python/blob/86cceb2bc914362e0990459002976c7e5a271e1d/lib/mysql/connector/connection_cext.py#L148
I also decided against the `callable` function as it seems to not exist in some versions of Python 3. I'm not sure which versions you officially support: https://docs.python.org/3/library/functions.html#callable .
--
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:
users@infra.apache.org