Skip to content

Commit

Permalink
Don't install SQLAlchemy/Pendulum adapters for other DBs (#18745)
Browse files Browse the repository at this point in the history
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 d75cf4d)
  • Loading branch information
ashb authored and jedcunningham committed Oct 20, 2021
1 parent f3f0eb2 commit 478f94b
Showing 1 changed file with 13 additions and 13 deletions.
26 changes: 13 additions & 13 deletions airflow/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down

0 comments on commit 478f94b

Please sign in to comment.