From 23a14f29da6607ee78f95c4bff9af7768c6e7954 Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Tue, 14 Jun 2011 10:08:34 -0400 Subject: [PATCH] - Fixed declarative bug where a class inheriting from a superclass of the same name would fail due to an unnecessary lookup of the name in the _decl_class_registry. [ticket:2194] --- CHANGES | 5 +++++ lib/sqlalchemy/ext/declarative.py | 3 +-- test/ext/test_declarative.py | 19 ++++++++++++++++--- 3 files changed, 22 insertions(+), 5 deletions(-) diff --git a/CHANGES b/CHANGES index 2048a8aa18..8a8c6d04f5 100644 --- a/CHANGES +++ b/CHANGES @@ -18,6 +18,11 @@ CHANGES in the way that occurs if you called it on Query().subquery(). [ticket:2190] + - Fixed declarative bug where a class inheriting + from a superclass of the same name would fail + due to an unnecessary lookup of the name + in the _decl_class_registry. [ticket:2194] + - mssql - Adjusted the pyodbc dialect such that bound values are passed as bytes and not unicode diff --git a/lib/sqlalchemy/ext/declarative.py b/lib/sqlalchemy/ext/declarative.py index 62a1170527..86fa8f3553 100755 --- a/lib/sqlalchemy/ext/declarative.py +++ b/lib/sqlalchemy/ext/declarative.py @@ -1038,8 +1038,7 @@ def _as_declarative(cls, classname, dict_): if 'inherits' not in mapper_args: for c in cls.__bases__: if _is_mapped_class(c): - mapper_args['inherits'] = cls._decl_class_registry.get( - c.__name__, None) + mapper_args['inherits'] = c break if hasattr(cls, '__mapper_cls__'): diff --git a/test/ext/test_declarative.py b/test/ext/test_declarative.py index 709560dd09..1adaf6e5fa 100644 --- a/test/ext/test_declarative.py +++ b/test/ext/test_declarative.py @@ -1272,7 +1272,7 @@ class DeclarativeInheritanceTest(DeclarativeTestBase): assert 'inherits' not in Person.__mapper_args__ assert class_mapper(Engineer).polymorphic_identity is None assert class_mapper(Engineer).polymorphic_on is Person.__table__.c.type - + def test_we_must_only_copy_column_mapper_args(self): class Person(Base): @@ -1292,8 +1292,8 @@ class DeclarativeInheritanceTest(DeclarativeTestBase): } assert class_mapper(Person).version_id_col == 'a' assert class_mapper(Person).include_properties == set(['id', 'a', 'b']) - - + + def test_custom_join_condition(self): class Foo(Base): @@ -2001,6 +2001,19 @@ class DeclarativeInheritanceTest(DeclarativeTestBase): assert_raises_message(sa.exc.ArgumentError, 'place __table_args__', go) + @testing.emits_warning("The classname") + def test_dupe_name_in_hierarchy(self): + class A(Base): + __tablename__ = "a" + id = Column( Integer, primary_key=True) + a_1 = A + class A(a_1): + __tablename__ = 'b' + + id = Column(Integer(),ForeignKey(a_1.id), primary_key = True) + + assert A.__mapper__.inherits is a_1.__mapper__ + def test_concrete(self): engineers = Table('engineers', Base.metadata, Column('id', Integer, primary_key=True, -- 2.39.5