Conversation
OpenAPI ChangesShow/hide ## Changes for v0.yaml:Unexpected changes? Ensure your branch is up-to-date with |
Comment on lines
+1857
to
+1867
| total_price_paid=0, | ||
| ) | ||
| line = Line.objects.create( | ||
| order=order, | ||
| purchased_object_id=product.object_id, | ||
| purchased_content_type_id=product.content_type_id, | ||
| product_version=product_version, | ||
| quantity=1, | ||
| ) | ||
| order.total_price_paid = line.discounted_price | ||
| order.save(update_fields=["total_price_paid"]) |
There was a problem hiding this comment.
Bug: The HubSpot cart tracking function creates permanent Order records that interfere with the actual ecommerce checkout flow, causing potential state corruption.
Severity: HIGH
Suggested Fix
Do not create persistent Order records for tracking purposes. If database records are necessary, ensure they are created and rolled back within the same transaction as the HubSpot API call. Alternatively, use a non-persistent model or a different tracking mechanism that does not interfere with the core ecommerce models.
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: hubspot_sync/api.py#L1853-L1867
Potential issue: The function `track_cart_add_with_hubspot` creates and commits a new
`Order` with `state=PENDING` to the database before making an external API call to
HubSpot. These tracking orders are not intended for checkout but persist in the
database. When a user proceeds to the actual checkout, the
`PendingOrder._get_or_create()` method finds and reuses these tracking orders because
they match the query criteria. This leads to state corruption, as the reused order has
incorrect data (e.g., `total_price_paid=0`) and can cause issues with discount
application and order processing.
Did we get this right? 👍 / 👎 to inform future reviews.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
James Kachel
cp-at-mit