From d86bb8afee43b742e1dc650dfabeda38b6b4f639 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 fc2c6bbbef8e0..1e9b931408c7f 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():