Commit ecb15c4a authored by Stephen Finucane's avatar Stephen Finucane
Browse files

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: default avatarStephen Finucane <stephenfin@redhat.com>
parent e1039e08
......@@ -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 .*',
......
......@@ -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):
......
......@@ -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):
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment