]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
- Fixed declarative bug where a class inheriting
authorMike Bayer <mike_mp@zzzcomputing.com>
Tue, 14 Jun 2011 14:08:34 +0000 (10:08 -0400)
committerMike Bayer <mike_mp@zzzcomputing.com>
Tue, 14 Jun 2011 14:08:34 +0000 (10:08 -0400)
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
lib/sqlalchemy/ext/declarative.py
test/ext/test_declarative.py

diff --git a/CHANGES b/CHANGES
index 2048a8aa1882d1de374223c69b311148b5de1eba..8a8c6d04f5cfc24c9f01d43c6725f8bca49ded3a 100644 (file)
--- 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
index 62a1170527a4da8620fcc78f5206b4083d7e021d..86fa8f3553352e579461b6797acb7b5f54817a43 100755 (executable)
@@ -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__'):
index 709560dd09e1f1e22d9a5de1bd17bfc32cc887fc..1adaf6e5fa98da3271f964a6bf88d6ef69996395 100644 (file)
@@ -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,