From c2060e8943e628404d9620ad60787c6af0a12b07 Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Tue, 23 Feb 2010 00:39:35 +0000 Subject: [PATCH] - the __mapper_args__ dict is copied when propagating to a subclass. Still need to decide how the argument propagation should work in the bigger picture. [ticket:1393] --- CHANGES | 6 +++++- lib/sqlalchemy/ext/declarative.py | 2 +- test/ext/test_declarative.py | 13 +++++++++++++ 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/CHANGES b/CHANGES index a587b3b04b..1c29c4787b 100644 --- a/CHANGES +++ b/CHANGES @@ -165,7 +165,11 @@ CHANGES (which when using DeclarativeMeta is cls.__dict__). This should in theory make it easier for custom metaclasses to modify the state passed into _as_declarative. - + + - the __mapper_args__ dict is copied when propagating to a subclass. + Still need to decide how the argument propagation should + work in the bigger picture. [ticket:1393] + - mysql - Fixed reflection bug whereby when COLLATE was present, nullable flag and server defaults would not be reflected. diff --git a/lib/sqlalchemy/ext/declarative.py b/lib/sqlalchemy/ext/declarative.py index d5bd2906b1..cc972fc6f7 100644 --- a/lib/sqlalchemy/ext/declarative.py +++ b/lib/sqlalchemy/ext/declarative.py @@ -500,7 +500,7 @@ def _as_declarative(cls, classname, dict_): raise exceptions.ArgumentError( "Can't add additional column %r when specifying __table__" % key) - mapper_args = getattr(cls, '__mapper_args__', {}) + mapper_args = dict(getattr(cls, '__mapper_args__', {})) if 'inherits' not in mapper_args: for c in cls.__bases__: if _is_mapped_class(c): diff --git a/test/ext/test_declarative.py b/test/ext/test_declarative.py index 9c60e01f3c..ad99727563 100644 --- a/test/ext/test_declarative.py +++ b/test/ext/test_declarative.py @@ -918,6 +918,19 @@ class DeclarativeTest(DeclarativeTestBase): class DeclarativeInheritanceTest(DeclarativeTestBase): + + def test_we_must_copy_mapper_args(self): + class Person(Base): + __tablename__ = 'people' + id = Column(Integer, primary_key=True) + discriminator = Column('type', String(50)) + __mapper_args__ = {'polymorphic_on': discriminator} + + class Engineer(Person): + primary_language = Column(String(50)) + + assert 'inherits' not in Person.__mapper_args__ + def test_custom_join_condition(self): class Foo(Base): __tablename__ = 'foo' -- 2.47.3