On Thu, Aug 3, 2017 at 1:37 PM, Colton Allen <cmanalle...@gmail.com> wrote: > I've got an event that's trying to update another model with a foreign key > but it's raising a strange error that I'm having trouble debugging. > "AttributeError: 'Join' object has no attribute 'implicit_returning'". > > The query worked in the past (before the OutboundModel became polymorphic). > I'm certain the query in the update event is incorrect but I'm unsure of how > to fix it. > > # Parent polymorphic models > class OutboundModel(Model): > __tablename__ = 'outbound' > > id = Column(Integer, primary_key=True) > driver = Column( > Enum('default', 'ses', name='outbound_driver'), default='default', > nullable=False) > latest_result_id = Column(Integer, ForeignKey('outbound_result.id')) > latest_result = orm.relationship( > 'OutboundResultModel', backref='outbound', > foreign_keys=[latest_result_id]) > > __mapper_args__ = { > 'polymorphic_identity': 'default', > 'polymorphic_on': driver, > 'with_polymorphic': '*' > } > > > class OutboundSESModel(OutboundModel): > __tablename__ = 'service_outbound_ses' > __mapper_args__ = {'polymorphic_identity': 'ses'} > > id = Column(Integer, ForeignKey('outbound.id'), primary_key=True) > > > # Child polymorphic models > class OutboundResultModel(Model): > __tablename__ = 'outbound_result' > > id = Column(Integer, primary_key=True) > driver = Column( > Enum('a', 'b', name='outbound_result_driver'), default='a', > nullable=False) > outbound_id = Column( > Integer, ForeignKey('outbound.id'), nullable=False) > outbound = orm.relationship( > 'OutboundModel', backref='results', foreign_keys=[outbound_id]) > __mapper_args__ = { > 'polymorphic_identity': 'result', > 'polymorphic_on': kind, > 'with_polymorphic': '*' > } > > > # The event causing the error. > # AttributeError: 'Join' object has no attribute 'implicit_returning' > @event.listens_for(OutboundResultModel, 'after_insert', propagate=True) > def set_latest_outbound_result(mapper, connection, target): > """Set the latest_outbound relationship on the Outbound parent.""" > statement = update(OutboundModel).where( > OutboundModel.id == target.outbound_id).values( > latest_result_id=target.id) > connection.execute(statement)
That's Core update(), which is probably not appreciating that OutboundModel now maps to a join() because of the with_polymorphic in the mapper config. If you're doing Core you should call upon OutboundModel.__table__ to eliminate any interference from the mapping (or if that doesn't work, because i can't remember if __table__ is going to pull in the polymorphic selectable as well, do inspect(OutboundModel).local_table). > > > -- > SQLAlchemy - > The Python SQL Toolkit and Object Relational Mapper > > http://www.sqlalchemy.org/ > > To post example code, please provide an MCVE: Minimal, Complete, and > Verifiable Example. See http://stackoverflow.com/help/mcve for a full > description. > --- > 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 https://groups.google.com/group/sqlalchemy. > For more options, visit https://groups.google.com/d/optout. -- SQLAlchemy - The Python SQL Toolkit and Object Relational Mapper http://www.sqlalchemy.org/ To post example code, please provide an MCVE: Minimal, Complete, and Verifiable Example. See http://stackoverflow.com/help/mcve for a full description. --- 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 https://groups.google.com/group/sqlalchemy. For more options, visit https://groups.google.com/d/optout.