[英]Why am I getting index error exception error?
try:
# recheck this bank detail lookup, can optimize this
# Known fact: as getting bank details and making refund is not in sync, we have bank_details against
# one of the shipment id, so not sure of refund will go against specific bank details.
# Current policy: taking latest one
user_obj = self.session.query(User).filter_by(id=self.order_obj.user_id).one()
current_shipment_id = self.shipment_id
current_shipment_obj = self.session.query(Shipment).filter_by(id=current_shipment_id).one()
prev_shipment_id = current_shipment_obj.previous_shipment_id
bank_account_details = self.session.query(BankAccount).filter(
BankAccount.affiliate_order_id==self.order_obj.affiliate_order_id,
BankAccount.user_id==user_obj.mongo_user_id,
BankAccount.shipment_id.in_([current_shipment_id, prev_shipment_id])
).order_by(desc('created_ts')).all()[0] # IndexError
except IndexError:
logger.exception("Unable to process refund, as no bank details found")
{bag_id: 51156, current_awb_no: 'null', current_shipment_id: '16266090343871907281J', forward_awb_no: 'null', forward_shipment_id: 'null', invoice_no: 'null', jm_order payment_182id: '16266090343871907281J'超出范圍
因為這個說法
self.session.query(BankAccount).filter(
BankAccount.affiliate_order_id==self.order_obj.affiliate_order_id,
BankAccount.user_id==user_obj.mongo_user_id,
BankAccount.shipment_id.in_([current_shipment_id, prev_shipment_id])
).order_by(desc('created_ts')).all()
長度小於 1,並且不可能從空列表中獲取第一個元素。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.