Fix for pay invoice internal server error#1164
Conversation
| order_obj[0].basket = "Saved" | ||
|
|
||
| if order_obj[0].basket.status == 'Saved' : |
There was a problem hiding this comment.
Bug: Assigning string "Saved" to order_obj[0].basket (a ForeignKey) causes AttributeError when status is accessed, leading to a crash.
Severity: CRITICAL | Confidence: High
🔍 Detailed Analysis
Line 879 incorrectly assigns the string literal "Saved" to order_obj[0].basket, which is a ForeignKey field expecting a Basket model object. This overwrites the object reference with a string. Subsequently, when line 881 attempts to access order_obj[0].basket.status, it results in an AttributeError: 'str' object has no attribute 'status', causing a server crash. This occurs when an invoice is 'unpaid', an order exists with an 'Open' basket, and the get_basket_for_future_invoice API is called.
💡 Suggested Fix
Remove line 879 as the database is already updated. Alternatively, update the in-memory object correctly using order_obj[0].basket.status = 'Saved' or order_obj[0].basket.refresh_from_db().
🤖 Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent.
Verify if this is a real issue. If it is, propose a fix; if not, explain why it's not
valid.
Location: ledgergw/api.py#L879-L881
Potential issue: Line 879 incorrectly assigns the string literal "Saved" to
`order_obj[0].basket`, which is a `ForeignKey` field expecting a `Basket` model object.
This overwrites the object reference with a string. Subsequently, when line 881 attempts
to access `order_obj[0].basket.status`, it results in an `AttributeError: 'str' object
has no attribute 'status'`, causing a server crash. This occurs when an invoice is
'unpaid', an order exists with an 'Open' basket, and the `get_basket_for_future_invoice`
API is called.
Did we get this right? 👍 / 👎 to inform future reviews.
Reference ID: 5466129
No description provided.