From 478f94b843a2963fde3150c9eec8846d797abd9a Mon Sep 17 00:00:00 2001 From: Ash Berlin-Taylor Date: Wed, 20 Oct 2021 19:56:10 +0100 Subject: [PATCH] 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 9a456ba77a539..7f5a2559fde19 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():