diff options
author | Mike Bayer <mike_mp@zzzcomputing.com> | 2020-08-24 12:00:04 -0400 |
---|---|---|
committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2020-12-11 13:18:42 -0500 |
commit | f37269ae603bc0e09210379e03a476ff2193c74c (patch) | |
tree | a46f4b0d571c04eb58a53a21547fe9399690d5b8 /oslo_db/sqlalchemy | |
parent | aad193a6dc2d3c93f5cc2209ec6cd3d9046b091c (diff) | |
download | oslo-db-f37269ae603bc0e09210379e03a476ff2193c74c.tar.gz |
Accommodate immutable URL api
SQLAlchemy 1.4 has modified the URL object to be immutable.
This patch makes the adjustments needed, using duck-typing
to check if the URL object is of the new style. When
requirements reach SQLAlchemy 1.4 as the minimum required
version, these conditionals should be removed in favor of
the noted option in each.
Change-Id: Id2f0663b13ed0f81e91a8d44f73d8541015bf844
Diffstat (limited to 'oslo_db/sqlalchemy')
-rw-r--r-- | oslo_db/sqlalchemy/engines.py | 12 | ||||
-rw-r--r-- | oslo_db/sqlalchemy/provision.py | 11 |
2 files changed, 21 insertions, 2 deletions
diff --git a/oslo_db/sqlalchemy/engines.py b/oslo_db/sqlalchemy/engines.py index 25215b9..0e19c18 100644 --- a/oslo_db/sqlalchemy/engines.py +++ b/oslo_db/sqlalchemy/engines.py @@ -105,6 +105,14 @@ def _setup_logging(connection_debug=0): def _extend_url_parameters(url, connection_parameters): + # TODO(zzzeek): remove hasattr() conditional when SQLAlchemy 1.4 is the + # minimum version in requirements; call update_query_string() + # unconditionally + if hasattr(url, "update_query_string"): + return url.update_query_string(connection_parameters, append=True) + + # TODO(zzzeek): remove the remainder of this method when SQLAlchemy 1.4 + # is the minimum version in requirements for key, value in parse.parse_qs( connection_parameters).items(): if key in url.query: @@ -118,6 +126,8 @@ def _extend_url_parameters(url, connection_parameters): if len(value) == 1: url.query[key] = value[0] + return url + def _vet_url(url): if "+" not in url.drivername and not url.drivername.startswith("sqlite"): @@ -153,7 +163,7 @@ def create_engine(sql_connection, sqlite_fk=False, mysql_sql_mode=None, url = sqlalchemy.engine.url.make_url(sql_connection) if connection_parameters: - _extend_url_parameters(url, connection_parameters) + url = _extend_url_parameters(url, connection_parameters) _vet_url(url) diff --git a/oslo_db/sqlalchemy/provision.py b/oslo_db/sqlalchemy/provision.py index 2fc3a54..5addab4 100644 --- a/oslo_db/sqlalchemy/provision.py +++ b/oslo_db/sqlalchemy/provision.py @@ -495,7 +495,16 @@ class BackendImpl(object, metaclass=abc.ABCMeta): """ url = sa_url.make_url(str(base_url)) - url.database = ident + + # TODO(zzzeek): remove hasattr() conditional in favor of "url.set()" + # when SQLAlchemy 1.4 is the minimum version in requirements + if hasattr(url, "set"): + url = url.set(database=ident) + else: + # TODO(zzzeek): remove when SQLAlchemy 1.4 + # is the minimum version in requirements + url.database = ident + return url |