0
我遇到一個500內部服務器錯誤在我DELETE DEF:Python的燒瓶刪除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鍊金術查詢運行正常,並且spend_for_flight
檢出(其他成功),並且航班成功刪除。當spend_for_flight >0
,我得到服務器錯誤。
感謝
調試500錯誤的第一步是在調試模式下運行,所以你可以看到回溯。 'app.run(debug = True)' – davidism