From 0230f2b99ae269fa2dc74825f950b0ea53436779 Mon Sep 17 00:00:00 2001 From: Ash Berlin-Taylor Date: Thu, 23 Aug 2018 10:55:46 +0100 Subject: [PATCH] [AIRFLOW-2574] Cope with '%' in SQLA DSN when running migrations Alembic uses a ConfigParser like Airflow does, and "%% is a special value in there, so we need to escape it. As per the Alembic docs: > Note that this value is passed to ConfigParser.set, which supports > variable interpolation using pyformat (e.g. `%(some_value)s`). A raw > percent sign not part of an interpolation symbol must therefore be > escaped, e.g. `%%` --- airflow/utils/db.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/airflow/utils/db.py b/airflow/utils/db.py index b57b8cf92b3cb..a10fd38b05eaa 100644 --- a/airflow/utils/db.py +++ b/airflow/utils/db.py @@ -342,8 +342,8 @@ def upgradedb(): package_dir = os.path.normpath(os.path.join(current_dir, '..')) directory = os.path.join(package_dir, 'migrations') config = Config(os.path.join(package_dir, 'alembic.ini')) - config.set_main_option('script_location', directory) - config.set_main_option('sqlalchemy.url', settings.SQL_ALCHEMY_CONN) + config.set_main_option('script_location', directory.replace('%', '%%')) + config.set_main_option('sqlalchemy.url', settings.SQL_ALCHEMY_CONN.replace('%', '%%')) command.upgrade(config, 'heads')