From 33b103b1f2876341c51cc32216e1fa8739ce8d58 Mon Sep 17 00:00:00 2001 From: Sergey Lyapustin Date: Mon, 20 Jun 2022 22:09:29 +0200 Subject: [PATCH 1/3] Patch sql_alchemy_conn if old postgres schemes used --- airflow/configuration.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/airflow/configuration.py b/airflow/configuration.py index 84df81812c6bf..a09d99ecd6d39 100644 --- a/airflow/configuration.py +++ b/airflow/configuration.py @@ -362,21 +362,21 @@ def _upgrade_auth_backends(self): ) def _upgrade_postgres_metastore_conn(self): - """As of sqlalchemy 1.4, scheme `postgres+psycopg2` must be replaced with `postgresql`""" + """As of SQLAlchemy 1.4, schemes `postgres+psycopg2` and `postgres` must be replaced with `postgresql`""" section, key = 'database', 'sql_alchemy_conn' old_value = self.get(section, key) - bad_scheme = 'postgres+psycopg2' + bad_schemes = ['postgres+psycopg2', 'postgres'] good_scheme = 'postgresql' parsed = urlparse(old_value) - if parsed.scheme == bad_scheme: + if parsed.scheme in bad_schemes: warnings.warn( - f"Bad scheme in Airflow configuration core > sql_alchemy_conn: `{bad_scheme}`. " - "As of SqlAlchemy 1.4 (adopted in Airflow 2.3) this is no longer supported. You must " + f"Bad scheme in Airflow configuration core > sql_alchemy_conn: `{parsed.scheme}`. " + "As of SQLAlchemy 1.4 (adopted in Airflow 2.3) this is no longer supported. You must " f"change to `{good_scheme}` before the next Airflow release.", FutureWarning, ) self.upgraded_values[(section, key)] = old_value - new_value = re.sub('^' + re.escape(f"{bad_scheme}://"), f"{good_scheme}://", old_value) + new_value = re.sub('^' + re.escape(f"{parsed.scheme}://"), f"{good_scheme}://", old_value) self._update_env_var(section=section, name=key, new_value=new_value) # if the old value is set via env var, we need to wipe it From dd7200f068be642ba540d2ff62b8c1f7be7ffc6f Mon Sep 17 00:00:00 2001 From: Sergey Lyapustin Date: Tue, 21 Jun 2022 19:29:29 +0200 Subject: [PATCH 2/3] Fixed long line in the docstring. --- airflow/configuration.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/airflow/configuration.py b/airflow/configuration.py index a09d99ecd6d39..d083696b7ea2f 100644 --- a/airflow/configuration.py +++ b/airflow/configuration.py @@ -362,7 +362,9 @@ def _upgrade_auth_backends(self): ) def _upgrade_postgres_metastore_conn(self): - """As of SQLAlchemy 1.4, schemes `postgres+psycopg2` and `postgres` must be replaced with `postgresql`""" + """ + As of SQLAlchemy 1.4, schemes `postgres+psycopg2` and `postgres` must be replaced with `postgresql`. + """ section, key = 'database', 'sql_alchemy_conn' old_value = self.get(section, key) bad_schemes = ['postgres+psycopg2', 'postgres'] From d599d8b8dfd318bee172b6043589744b3b0f12c2 Mon Sep 17 00:00:00 2001 From: Sergey Lyapustin Date: Tue, 21 Jun 2022 22:42:52 +0200 Subject: [PATCH 3/3] Fixed docstring. --- airflow/configuration.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/airflow/configuration.py b/airflow/configuration.py index d083696b7ea2f..e8d592dacb100 100644 --- a/airflow/configuration.py +++ b/airflow/configuration.py @@ -363,7 +363,8 @@ def _upgrade_auth_backends(self): def _upgrade_postgres_metastore_conn(self): """ - As of SQLAlchemy 1.4, schemes `postgres+psycopg2` and `postgres` must be replaced with `postgresql`. + As of SQLAlchemy 1.4, schemes `postgres+psycopg2` and `postgres` + must be replaced with `postgresql`. """ section, key = 'database', 'sql_alchemy_conn' old_value = self.get(section, key)