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:
parent
a09d70780e
commit
493cee3531
@ -174,7 +174,9 @@ def _create_context_manager():
|
|||||||
_ctx_mgr = enginefacade.transaction_context()
|
_ctx_mgr = enginefacade.transaction_context()
|
||||||
# TODO(aarefiev): enable foreign keys for SQLite once all unit
|
# TODO(aarefiev): enable foreign keys for SQLite once all unit
|
||||||
# tests with failed constraint will be fixed.
|
# 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
|
return _ctx_mgr
|
||||||
|
|
||||||
|
@ -53,7 +53,10 @@ class TestDB(test_base.NodeTest):
|
|||||||
|
|
||||||
ctx_mgr = db._create_context_manager()
|
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)
|
self.assertEqual(mock_ctx_mgr, ctx_mgr)
|
||||||
|
|
||||||
@mock.patch.object(db, 'get_context_manager', autospec=True)
|
@mock.patch.object(db, 'get_context_manager', autospec=True)
|
||||||
|
@ -56,8 +56,10 @@ def patch_with_engine(engine):
|
|||||||
autospec=True) as patch_w_sess, \
|
autospec=True) as patch_w_sess, \
|
||||||
mock.patch.object(db, 'get_reader_session',
|
mock.patch.object(db, 'get_reader_session',
|
||||||
autospec=True) as patch_r_sess:
|
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 = (
|
patch_w_sess.return_value = patch_r_sess.return_value = (
|
||||||
orm.get_maker(engine)())
|
orm.get_maker(engine, autocommit=True)())
|
||||||
yield
|
yield
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user