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)


-- 
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 [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.

Reply via email to