Skip to content

Commit

Permalink
Fix compatibility with oslo.db 12.1.0
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
dtantsur and stephenfin committed Sep 8, 2022
1 parent a09d707 commit 493cee3
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
4 changes: 3 additions & 1 deletion ironic_inspector/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
5 changes: 4 additions & 1 deletion ironic_inspector/test/unit/test_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,10 @@ def test__create_context_manager(self, mock_cnxt):

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)
Expand Down
4 changes: 3 additions & 1 deletion ironic_inspector/test/unit/test_migrations.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down

0 comments on commit 493cee3

Please sign in to comment.