From 493cee3531d59c32a99ce3534d0c07539c06be27 Mon Sep 17 00:00:00 2001 From: Dmitry Tantsur Date: Thu, 8 Sep 2022 13:43:14 +0200 Subject: [PATCH] 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 --- ironic_inspector/db.py | 4 +++- ironic_inspector/test/unit/test_db.py | 5 ++++- ironic_inspector/test/unit/test_migrations.py | 4 +++- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/ironic_inspector/db.py b/ironic_inspector/db.py index ae00081e6..cfa2b1120 100644 --- a/ironic_inspector/db.py +++ b/ironic_inspector/db.py @@ -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 diff --git a/ironic_inspector/test/unit/test_db.py b/ironic_inspector/test/unit/test_db.py index c7134a6ad..f73ca338c 100644 --- a/ironic_inspector/test/unit/test_db.py +++ b/ironic_inspector/test/unit/test_db.py @@ -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) diff --git a/ironic_inspector/test/unit/test_migrations.py b/ironic_inspector/test/unit/test_migrations.py index 7f101c750..6f8715588 100644 --- a/ironic_inspector/test/unit/test_migrations.py +++ b/ironic_inspector/test/unit/test_migrations.py @@ -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