ConcreteBase (0.7.3) only supporting 1 level of inheritance ?

38 views
Skip to first unread message

JPLaverdure

unread,
Oct 28, 2011, 12:27:45 PM10/28/11
to sqlal...@googlegroups.com
Hello,

I started playing with Concrete Table Inheritance this morning and tried to implement a portion of my schema:

class Mixin(object):
    __table_args__ = {'schema':'test'}

    id = Column(Integer, primary_key=True)


class Node(ConcreteBase, Base, Mixin):
    __tablename__ = 'node'
    __mapper_args__ = {'polymorphic_identity':'node', 'concrete':True}


class Sample(Node, Mixin):
    __tablename__ = 'sample'
    __mapper_args__ = {'polymorphic_identity':'sample', 'concrete':True}


class DNA(Sample, Mixin):
    __tablename__ = 'dna'
    __mapper_args__ = {'polymorphic_identity':'dna', 'concrete':True}
    
    token = Column(String(128), nullable=False)
    qty = Column(Integer, nullable=False)
    comments = Column(String(256))
    
    def __init__(self, token, qty, comments=None):
        self.token = token
        self.qty = qty
        self.comments = comments

    def __repr__(self):
        return """<Sample(%s, %s, Qty: %s)>""" % (self.id, self.token, self.qty)


class RNA(Sample, Mixin):
    __tablename__ = 'rna'
    __mapper_args__ = {'polymorphic_identity':'rna', 'concrete':True}
    
    token = Column(String(128), nullable=False)
    qty = Column(Integer, nullable=False)
    comments = Column(String(256))
    
    def __init__(self, token, qty, comments=None):
        self.token = token
        self.qty = qty
        self.comments = comments

    def __repr__(self):
        return """<RNA(%s, %s, Qty: %s)>""" % (self.id, self.token, self.qty)

But after inserting some DNA and RNA entities...
It seems that:

session.query(Node).all() 

returns an empty list whereas:

session.query(Sample).all()

returns a polymorphic list of RNAs and DNAs...
Am I missing something ?


Also:
If I declare Node as per:
 
class Node(AbstractConcreteBase, Base):
   pass

Instead of above, I get the following error:
 assert mapper is mapper.base_mapper
AssertionError

In a perfect world, I would have both Node and Sample as abstract classes but I can't seem to get that going..

Any pointers ?
Thanks !



Michael Bayer

unread,
Oct 28, 2011, 1:59:23 PM10/28/11
to sqlal...@googlegroups.com
this is why I hate adding new features, b.c. now i have to support them, though concrete with declarative really needed a push.    The abstract concrete bases have probably not yet been tested with multiple-level inheritance.  Hard to say where things are going wrong without running a test and pdb'ing...if you want to help out you can attach a full reproducible test case as a ticket to http://www.sqlalchemy.org/trac/newticket , log in as "guest"/"guest".



--
You received this message because you are subscribed to the Google Groups "sqlalchemy" group.
To view this discussion on the web visit https://groups.google.com/d/msg/sqlalchemy/-/xojj7cGtMqcJ.
To post to this group, send email to sqlal...@googlegroups.com.
To unsubscribe from this group, send email to sqlalchemy+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en.

JPLaverdure

unread,
Oct 28, 2011, 2:28:47 PM10/28/11
to sqlal...@googlegroups.com
Hello Michael,

Sorry to be the thorn in your side.. 
I attached a test case as requested.. Ticket 2312.

Also, it seems this is incompatible with history_meta based versioning.
(Which probably has to do with the use of the 
"__declare_last__()"
function.

Thank you

Michael Bayer

unread,
Oct 28, 2011, 6:52:10 PM10/28/11
to sqlal...@googlegroups.com
On Oct 28, 2011, at 2:28 PM, JPLaverdure wrote:

Hello Michael,

Sorry to be the thorn in your side.. 
I attached a test case as requested.. Ticket 2312.

thanks for the ticket and this is fixed in radadaccc1bb5 .

Also, it seems this is incompatible with history_meta based versioning.
(Which probably has to do with the use of the 
function.

I can sort of see that, but not quite - in this recipe, all the columns/tables are created as they normally are, not within __declare_last__(), unless I guess you want __history_mapper__ on the abstract base with the same polymorphic setup.....  The patch attached to http://www.sqlalchemy.org/trac/ticket/2313 may achieve part of this, but I don't know about the "polymorphic" loader, would that ever have worked with the history_meta system ?   I would think history_meta would need special steps to work along with polymorphic selectables.    

Reply all
Reply to author
Forward
0 new messages