diff options
author | Stephen Finucane <stephenfin@redhat.com> | 2023-04-05 13:19:34 +0100 |
---|---|---|
committer | Stephen Finucane <stephenfin@redhat.com> | 2023-04-06 14:54:40 +0100 |
commit | 1f003bcb0b74cecbfe24f52402328b76a07c9983 (patch) | |
tree | 8a1ca406db245f51d7ecebf6f61a39f8172b8dec /oslo_db/sqlalchemy/compat | |
parent | da4f13e7345653eba8aab5b8aceeaeff7367989e (diff) | |
download | oslo-db-1f003bcb0b74cecbfe24f52402328b76a07c9983.tar.gz |
Get test suite to full pass with SQLAlchemy 2.0
Remaining issues encountered when running with SQLAlchemy 2.0 for real:
* Never call str() on a URL and expect it to be meaningful anymore.
The password is aggressively obfuscated now (users absolultely
wouldn't let us leave it as is)
* More utilities and fixtures that were calling begin() within a
block that would have already begun
* isnot is now called is_not; mocking "isnot" leads into too many
weird compat layers
* ORM InstrumentedAttribute and internals use __slots__ now, mock
seems to not be able to patch methods. Ideally these tests would use
a comparator subclass or something
* Connection.connection.connection is now called driver_connection,
SQLAlchemy keeps the old name available however oslo.db test suite
does not appear to tolerate the deprecation warning emitted,
so add a compat layer
* mapper() is fully removed from 2.0, not sure if there is another
not-yet-committed gerrit that removes mapper()
[1] https://docs.sqlalchemy.org/en/20/core/engines.html#sqlalchemy.create_engine.params.pool_pre_ping
[2] https://docs.sqlalchemy.org/en/20/changelog/changelog_20.html#change-2fe37eaf2295cebd3bb4ee8e5b8c575c
[3] https://github.com/sqlalchemy/sqlalchemy/issues/5648
Change-Id: Ifaca67c07f008d8bc0febeecd3e200cc7ee7a4b0
Diffstat (limited to 'oslo_db/sqlalchemy/compat')
-rw-r--r-- | oslo_db/sqlalchemy/compat/__init__.py | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/oslo_db/sqlalchemy/compat/__init__.py b/oslo_db/sqlalchemy/compat/__init__.py new file mode 100644 index 0000000..6713696 --- /dev/null +++ b/oslo_db/sqlalchemy/compat/__init__.py @@ -0,0 +1,36 @@ +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +from oslo_utils import versionutils + +from sqlalchemy import __version__ + + +_vers = versionutils.convert_version_to_tuple(__version__) +sqla_2 = _vers >= (2, ) + + +def dialect_from_exception_context(ctx): + if sqla_2: + # SQLAlchemy 2.0 still has context.engine, however if the + # exception context is called in the context of a ping handler, + # engine is not present. need to use dialect instead + return ctx.dialect + else: + return ctx.engine.dialect + + +def driver_connection(connection): + if sqla_2: + return connection.connection.driver_connection + else: + return connection.connection.connection |