Fix compatibility with oslo.db 12.1.0

oslo.db 12.1.0 has changed the default value for the 'autocommit'
parameter of 'LegacyEngineFacade' from 'True' to 'False'. This is a
necessary step to ensure compatibility with SQLAlchemy 2.0. However, we
are currently relying on the autocommit behavior and need changes to
explicitly manage sessions. Until that happens, we need to override the
default.

Change-Id: Ia6d512ff2ae417bab938cb095fbb0884d195010a
Co-authored-by: Stephen Finucane <stephenfin@redhat.com>
This commit is contained in:
Dmitry Tantsur 2022-09-08 13:43:14 +02:00 committed by Stephen Finucane
parent a09d70780e
commit 493cee3531
3 changed files with 10 additions and 3 deletions

View File

@ -174,7 +174,9 @@ def _create_context_manager():
_ctx_mgr = enginefacade.transaction_context()
# TODO(aarefiev): enable foreign keys for SQLite once all unit
# tests with failed constraint will be fixed.
_ctx_mgr.configure(sqlite_fk=False)
# FIXME(dtantsur): we need to remove reliance on autocommit semantics ASAP
# since it's not compatible with SQLAlchemy 2.0
_ctx_mgr.configure(sqlite_fk=False, __autocommit=True)
return _ctx_mgr

View File

@ -53,7 +53,10 @@ class TestDB(test_base.NodeTest):
ctx_mgr = db._create_context_manager()
mock_ctx_mgr.configure.assert_called_once_with(sqlite_fk=False)
mock_ctx_mgr.configure.assert_called_once_with(
sqlite_fk=False,
__autocommit=True,
)
self.assertEqual(mock_ctx_mgr, ctx_mgr)
@mock.patch.object(db, 'get_context_manager', autospec=True)

View File

@ -56,8 +56,10 @@ def patch_with_engine(engine):
autospec=True) as patch_w_sess, \
mock.patch.object(db, 'get_reader_session',
autospec=True) as patch_r_sess:
# FIXME(stephenfin): we need to remove reliance on autocommit semantics
# ASAP since it's not compatible with SQLAlchemy 2.0
patch_w_sess.return_value = patch_r_sess.return_value = (
orm.get_maker(engine)())
orm.get_maker(engine, autocommit=True)())
yield