This is an automated email from the ASF dual-hosted git repository.

jedcunningham pushed a commit to branch v2-2-test
in repository https://gitbox.apache.org/repos/asf/airflow.git

commit 478f94b843a2963fde3150c9eec8846d797abd9a
Author: Ash Berlin-Taylor <ash_git...@firemirror.com>
AuthorDate: Wed Oct 20 19:56:10 2021 +0100

    Don't install SQLAlchemy/Pendulum adapters for other DBs (#18745)
    
    This stops the MySQL libs being imported "unnecessarily" when Postgres
    is in use -- and there have been a few confusing reports of the mysql
    client libs causing problems in rare cases, so lets avoid the import if
    we can.
    
    (cherry picked from commit d75cf4d60ddbff5b88bfe348cb83f9d173187744)
---
 airflow/settings.py | 26 +++++++++++++-------------
 1 file changed, 13 insertions(+), 13 deletions(-)

diff --git a/airflow/settings.py b/airflow/settings.py
index 9a456ba..7f5a255 100644
--- a/airflow/settings.py
+++ b/airflow/settings.py
@@ -344,24 +344,24 @@ def configure_adapters():
     """Register Adapters and DB Converters"""
     from pendulum import DateTime as Pendulum
 
-    try:
+    if SQL_ALCHEMY_CONN.startswith('sqlite'):
         from sqlite3 import register_adapter
 
         register_adapter(Pendulum, lambda val: val.isoformat(' '))
-    except ImportError:
-        pass
-    try:
-        import MySQLdb.converters
 
-        MySQLdb.converters.conversions[Pendulum] = 
MySQLdb.converters.DateTime2literal
-    except ImportError:
-        pass
-    try:
-        import pymysql.converters
+    if SQL_ALCHEMY_CONN.startswith('mysql'):
+        try:
+            import MySQLdb.converters
 
-        pymysql.converters.conversions[Pendulum] = 
pymysql.converters.escape_datetime
-    except ImportError:
-        pass
+            MySQLdb.converters.conversions[Pendulum] = 
MySQLdb.converters.DateTime2literal
+        except ImportError:
+            pass
+        try:
+            import pymysql.converters
+
+            pymysql.converters.conversions[Pendulum] = 
pymysql.converters.escape_datetime
+        except ImportError:
+            pass
 
 
 def validate_session():

Reply via email to