]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
- Fixed "'NoneType' object has no attribute 'concrete'" error
authorMike Bayer <mike_mp@zzzcomputing.com>
Mon, 6 Oct 2014 22:33:05 +0000 (18:33 -0400)
committerMike Bayer <mike_mp@zzzcomputing.com>
Mon, 6 Oct 2014 22:33:05 +0000 (18:33 -0400)
when using :class:`.AbstractConcreteBase` in conjunction with
a subclass that declares ``__abstract__``.
fixes #3185

doc/build/changelog/changelog_09.rst
lib/sqlalchemy/ext/declarative/api.py
test/ext/declarative/test_inheritance.py

index 7dd50739e03b5feeee9ec14cea9095d5c6722b76..692c6e392505f419232797d1c5eb0d54da604b3d 100644 (file)
 .. changelog::
     :version: 0.9.8
 
+    .. change::
+        :tags: bug, declarative, orm
+        :versions: 1.0.0
+        :tickets: 3185
+
+        Fixed "'NoneType' object has no attribute 'concrete'" error
+        when using :class:`.AbstractConcreteBase` in conjunction with
+        a subclass that declares ``__abstract__``.
+
     .. change::
         :tags: bug, engine
         :versions: 1.0.0
index e84b21ad233074185f26ed0aebbb20b0b058834e..66fe05fd0e868874565375de9ae064d181479cac 100644 (file)
@@ -547,7 +547,7 @@ class AbstractConcreteBase(ConcreteBase):
 
         for scls in cls.__subclasses__():
             sm = _mapper_or_none(scls)
-            if sm.concrete and cls in scls.__bases__:
+            if sm and sm.concrete and cls in scls.__bases__:
                 sm._set_concrete_base(m)
 
 
index 5a99c9c5a7da17d640608339b00bc05a39293de2..6ea37e4d3b13843e8fbc3567f551004e2892cf80 100644 (file)
@@ -1388,3 +1388,32 @@ class ConcreteExtensionConfigTest(
             "WHERE something.id = pjoin.something_id AND something.id = :id_1)"
         )
 
+    def test_abstract_in_hierarchy(self):
+        class Document(Base, AbstractConcreteBase):
+            doctype = Column(String)
+
+        class ContactDocument(Document):
+            __abstract__ = True
+
+            send_method = Column(String)
+
+        class ActualDocument(ContactDocument):
+            __tablename__ = 'actual_documents'
+            __mapper_args__ = {
+                'concrete': True,
+                'polymorphic_identity': 'actual'}
+
+            id = Column(Integer, primary_key=True)
+
+        configure_mappers()
+        session = Session()
+        self.assert_compile(
+            session.query(Document),
+            "SELECT pjoin.doctype AS pjoin_doctype, "
+            "pjoin.send_method AS pjoin_send_method, "
+            "pjoin.id AS pjoin_id, pjoin.type AS pjoin_type "
+            "FROM (SELECT actual_documents.doctype AS doctype, "
+            "actual_documents.send_method AS send_method, "
+            "actual_documents.id AS id, 'actual' AS type "
+            "FROM actual_documents) AS pjoin"
+        )
\ No newline at end of file