diff options
-rw-r--r-- | oslo_db/sqlalchemy/enginefacade.py | 13 | ||||
-rw-r--r-- | oslo_db/tests/sqlalchemy/test_enginefacade.py | 12 |
2 files changed, 24 insertions, 1 deletions
diff --git a/oslo_db/sqlalchemy/enginefacade.py b/oslo_db/sqlalchemy/enginefacade.py index 0985ea8..111f033 100644 --- a/oslo_db/sqlalchemy/enginefacade.py +++ b/oslo_db/sqlalchemy/enginefacade.py @@ -622,6 +622,17 @@ class _TransactionContextManager(object): """ self._factory.configure(**kw) + def get_legacy_facade(self): + """Return a :class:`.LegacyEngineFacade` for factory from this context. + + This facade will make use of the same engine and sessionmaker + as this factory, however will not share the same transaction context; + the legacy facade continues to work the old way of returning + a new Session each time get_session() is called. + """ + + return self._factory.get_legacy_facade() + @property def replace(self): """Modifier to replace the global transaction factory with this one.""" @@ -827,7 +838,7 @@ def get_legacy_facade(): a new Session each time get_session() is called. """ - return _context_manager._factory.get_legacy_facade() + return _context_manager.get_legacy_facade() reader = _context_manager.reader diff --git a/oslo_db/tests/sqlalchemy/test_enginefacade.py b/oslo_db/tests/sqlalchemy/test_enginefacade.py index 4a2517e..62e3fa9 100644 --- a/oslo_db/tests/sqlalchemy/test_enginefacade.py +++ b/oslo_db/tests/sqlalchemy/test_enginefacade.py @@ -985,6 +985,18 @@ class LegacyIntegrationtest(test_base.DbTestCase): enginefacade._context_manager._factory._writer_maker ) + def test_legacy_facades_from_different_context_managers(self): + transaction_context1 = enginefacade.transaction_context() + transaction_context2 = enginefacade.transaction_context() + + transaction_context1.configure(connection='sqlite:///?conn1') + transaction_context2.configure(connection='sqlite:///?conn2') + + legacy1 = transaction_context1.get_legacy_facade() + legacy2 = transaction_context2.get_legacy_facade() + + self.assertNotEqual(legacy1, legacy2) + class ThreadingTest(test_base.DbTestCase): """Test copy/pickle on new threads using real connections and sessions.""" |