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 <stephenfin@redhat.com>
This commit is contained in:
Stephen Finucane 2021-07-19 11:40:08 +01:00
parent e1039e0849
commit ecb15c4ac6
3 changed files with 9 additions and 9 deletions

View File

@ -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 .*',

View File

@ -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):

View File

@ -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):