def polymorphic_update_timestamp(session, flush_context, instances):
    """This listener ensures an update statement is emited for "entity" table
    to update 'updated_at'.

    With joined-table inheritance if the only modified attributes are
    subclass's ones, then no update statement will be emitted.
    """
    for obj in session.dirty:
        if not isinstance(obj, Entity):
            continue
        state = sa.inspect(obj)
        history = state.attrs["updated_at"].history
        if not any((history.added, history.deleted)):
            obj.updated_at = datetime.utcnow()
This listener ensures an update statement is emited for "entity" table
    to update 'updated_at'.

    With joined-table inheritance if the only modified attributes are
    subclass's ones, then no update statement will be emitted.