From ecb15c4ac63772e3332ac0f475e852f414ca3bbb Mon Sep 17 00:00:00 2001 From: Stephen Finucane Date: Mon, 19 Jul 2021 11:40:08 +0100 Subject: [PATCH] Don't call mapper() outside of declarative registry Resolve the following RemovedIn20Warning: Calling the mapper() function directly outside of a declarative registry is deprecated. Please use the sqlalchemy.orm.registry.map_imperatively() function for a classical mapping. Change-Id: I92a7ccdd48eedd4c788384033743daf50a9dc113 Signed-off-by: Stephen Finucane --- oslo_db/tests/fixtures.py | 5 ----- oslo_db/tests/sqlalchemy/test_enginefacade.py | 6 ++++-- oslo_db/tests/sqlalchemy/test_exc_filters.py | 7 +++++-- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/oslo_db/tests/fixtures.py b/oslo_db/tests/fixtures.py index ccecccd4..0168116a 100644 --- a/oslo_db/tests/fixtures.py +++ b/oslo_db/tests/fixtures.py @@ -52,11 +52,6 @@ class WarningsFixture(fixtures.Fixture): message=r'The Engine.execute\(\) method is considered legacy .*', category=sqla_exc.SADeprecationWarning) - warnings.filterwarnings( - 'once', - message=r'Calling the mapper\(\) function directly outside .*', - category=sqla_exc.SADeprecationWarning) - warnings.filterwarnings( 'once', message=r'The current statement is being autocommitted .*', diff --git a/oslo_db/tests/sqlalchemy/test_enginefacade.py b/oslo_db/tests/sqlalchemy/test_enginefacade.py index b24892b8..a188d01e 100644 --- a/oslo_db/tests/sqlalchemy/test_enginefacade.py +++ b/oslo_db/tests/sqlalchemy/test_enginefacade.py @@ -24,7 +24,7 @@ from oslo_context import context as oslo_context from sqlalchemy import Column from sqlalchemy import Integer from sqlalchemy import MetaData -from sqlalchemy.orm import mapper +from sqlalchemy.orm import registry from sqlalchemy.orm import Session from sqlalchemy import select from sqlalchemy import String @@ -1671,11 +1671,13 @@ class LiveFacadeTest(db_test_base._DbTestCase): metadata.create_all(self.engine) self.addCleanup(metadata.drop_all, self.engine) + reg = registry() + class User(object): def __init__(self, name): self.name = name - mapper(User, user_table) + reg.map_imperatively(User, user_table) self.User = User def _assert_ctx_connection(self, context, connection): diff --git a/oslo_db/tests/sqlalchemy/test_exc_filters.py b/oslo_db/tests/sqlalchemy/test_exc_filters.py index a05c9a9c..27a37a4a 100644 --- a/oslo_db/tests/sqlalchemy/test_exc_filters.py +++ b/oslo_db/tests/sqlalchemy/test_exc_filters.py @@ -23,7 +23,7 @@ from sqlalchemy.engine import url as sqla_url from sqlalchemy import event import sqlalchemy.exc from sqlalchemy.orm import declarative_base -from sqlalchemy.orm import mapper +from sqlalchemy.orm import registry from sqlalchemy import sql from oslo_db import exception @@ -1046,10 +1046,13 @@ class IntegrationTest(db_test_base._DbTestCase): self.test_table.create(self.engine) self.addCleanup(self.test_table.drop, self.engine) + reg = registry() + class Foo(object): def __init__(self, counter): self.counter = counter - mapper(Foo, self.test_table) + + reg.map_imperatively(Foo, self.test_table) self.Foo = Foo def test_flush_wrapper_duplicate_entry(self):