Skip to content

More than one level of abstract concrete base classes does not work #3185

Closed
@sqlalchemy-bot

Description

@sqlalchemy-bot
Collaborator

Migrated issue, originally created by Alex Grönholm (@agronholm)

The following code fails with AttributeError: 'NoneType' object has no attribute 'concrete':

from sqlalchemy import *
from sqlalchemy.orm import *
from sqlalchemy.ext.declarative import AbstractConcreteBase, declarative_base

Base = declarative_base()


class Document(Base, AbstractConcreteBase):
    doctype = Column(Unicode, nullable=False)


class ContactDocument(Document):
    __abstract__ = True

    send_method = Column('sendmethod', Unicode)


class ActualDocument(ContactDocument):
    __tablename__ = 'actual_documents'
    __mapper_args__ = {'concrete': True, 'polymorphic_identity': 'actual'}

    id = Column(Integer, primary_key=True)

configure_mappers()

This is caused by the declare_first() in AbstractConcreteBase not checking if the target subclass has a mapper or not. Attached is the patch I was given to remedy the issue.


Attachments: api.diff

Activity

sqlalchemy-bot

sqlalchemy-bot commented on Sep 9, 2014

@sqlalchemy-bot
CollaboratorAuthor

Changes by Michael Bayer (@zzzeek):

  • set milestone to "0.9.8"
sqlalchemy-bot

sqlalchemy-bot commented on Oct 6, 2014

@sqlalchemy-bot
CollaboratorAuthor

Michael Bayer (@zzzeek) wrote:

5a10b6a

sqlalchemy-bot

sqlalchemy-bot commented on Oct 6, 2014

@sqlalchemy-bot
CollaboratorAuthor

Michael Bayer (@zzzeek) wrote:

Conflicts:
test/ext/declarative/test_inheritance.py

24cd39d

sqlalchemy-bot

sqlalchemy-bot commented on Oct 6, 2014

@sqlalchemy-bot
CollaboratorAuthor

Changes by Michael Bayer (@zzzeek):

  • changed status to closed
sqlalchemy-bot

sqlalchemy-bot commented on Apr 24, 2015

@sqlalchemy-bot
CollaboratorAuthor

Anatoly Bubenkov (@bubenkoff) wrote:

@zzzeek did it broke the former functionality of AbstractConcreteBase?

class BaseLock(AbstractConcreteBase, Base):

    """Base lock."""
    @declared_attr
    def ticket(cls):
        """:py:class:`paylogic.service.ticket.models.Ticket` relationship."""
        return relation('Ticket', backref=backref('{0}_locks'.format(
            cls.__mapper_args__['polymorphic_identity']), viewonly=True))

this fails with now:

KeyError: 'polymorphic_identity'

and declared_attr now receives BaseLock class in cls instead of concrete class

sqlalchemy-bot

sqlalchemy-bot commented on Apr 24, 2015

@sqlalchemy-bot
CollaboratorAuthor

Michael Bayer (@zzzeek) wrote:

@bubenkov - can you please provide a complete test case? at the moment it seems you are just hitting the same thing as #3383.

added
declarativehas to do with the declarative API, scanning classes and mixins for attributes to be mapped
bugSomething isn't working
on Nov 27, 2018
added this to the 0.9.8 milestone on Nov 27, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingdeclarativehas to do with the declarative API, scanning classes and mixins for attributes to be mappedlow priority

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @sqlalchemy-bot

        Issue actions

          More than one level of abstract concrete base classes does not work · Issue #3185 · sqlalchemy/sqlalchemy