Skip to content

Conversation

@xzzy
Copy link
Collaborator

@xzzy xzzy commented Dec 4, 2025

No description provided.

@xzzy xzzy merged commit 18c88bc into dbca-wa:master Dec 4, 2025
3 of 4 checks passed
Comment on lines +879 to +881
order_obj[0].basket = "Saved"

if order_obj[0].basket.status == 'Saved' :
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants