you have the same polymorphic_identity used for two different classes:

class BluePart(CommonPart):
    __tablename__ = 'blue_part'
    __mapper_args__ = {'polymorphic_identity': u'blue_part'}

    cp_id = Column(Integer, ForeignKey(CommonPart.id), primary_key=True)
    blue_property = Column(Unicode(20), nullable=True)



class FancyBluePart(module1.BluePart):
    __mapper_args__ = {'polymorphic_identity': u'blue_part'}

    def do_fancy_stuff(self):
        return self.id

And there's even a handy warning telling you as such:

mapper.py:984: SAWarning: Reassigning polymorphic association for identity u'blue_part' from <Mapper at 0x1033a7d90; BluePart> to <Mapper at 0x1033a7f10; FancyBluePart>: Check for duplicate use of u'blue_part' as value for polymorphic_identity.
  self, self.polymorphic_identity)


The FancyBluePart is assigned second, so it wins. The reason you see BluePart the first time around is because you've created BluePart in Python, you persist a row for that part and then re-load that row, the polymoprhic_identity isn't consulted; you already have the object in the identity map. Subsequent runs, the DB has that row in it already, you're just appending other rows, but you select that first one and identity takes effect and you get FBP.







On 7/30/15 6:42 AM, Marco wrote:
Hi,
I have a puzzling situation, exemplified in the included tarball. Basically I need to augment a class with some special behavior that is not present/desirable in the module where the class is defined. However, I find an unexpected type returned by session.query in spite of what I pass to it - this seems to be due to some module introspection done by the mapper that appears to be dependent on what modules are imported and in what order.
I'll be happy to learn of better ways to achieve the same end goal.
Cheers
Marco

--
You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To unsubscribe from this group and stop receiving emails from it, send an email to sqlalchemy+unsubscr...@googlegroups.com <mailto:sqlalchemy+unsubscr...@googlegroups.com>. To post to this group, send email to sqlalchemy@googlegroups.com <mailto:sqlalchemy@googlegroups.com>.
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.

Reply via email to