我在 DELETE def:
中遇到500内部服务器错误def delete(self, flight_id):
session = db.get_session()
try:
spend_for_flight = session.query(func.count(db.Snapshot.rowID))\
.join(db.Flight, db.Flight.strategy_id == db.Snapshot.strategy_id)\
.filter(and_(db.Snapshot.interval >= db.Flight.start_date, db.Snapshot.interval <= db.Flight.end_date, db.Flight.rowID == flight_id)).scalar();
# there is spend for at least one of these flight dates
if spend_for_flight > 0:
response = jsonify(error="Flight has spend. Cannot delete.")
response.status = 400
return response
elif spend_for_flight == 0:
session.query(db.Flight).filter(db.Flight.rowID == flight_id).delete()
session.commit()
return 204
except sqlalchemy.exc.SQLAlchemyError, exc:
session.rollback()
reason = exc.message
response = jsonify(error=reason)
response.status_code = 501
return response
finally:
session.close()
错误发生在if
语句中。 SQL alchemy查询运行正常并且spend_for_flight
检出(其他成功)并且航班成功删除。 spend_for_flight >0
时,我收到服务器错误。
由于
答案 0 :(得分:1)
您应该使用status_code
代替status
,就像使用501
一样。也就是说,而不是:
response.status = 400
写
response.status_code = 400