fix: recover overlapping Stripe webhook order creation - #559
Open
bseverino wants to merge 2 commits into
Open
Conversation
Co-authored-by: Cursor <cursoragent@cursor.com>
Let authoritative CommerceTools lookup failures drive Celery retries instead of masking them with the original create error. Co-authored-by: Cursor <cursoragent@cursor.com>
Coverage reportClick to see where and how coverage changed
This report was generated by python-coverage-comment-action |
||||||||||||||||||||||||||||||||||||
Contributor
There was a problem hiding this comment.
Pull request overview
Updates Stripe payment finalization to recover from overlapping order creation by re-querying CommerceTools and healing existing orders.
Changes:
- Re-query and recover existing orders after creation failures.
- Prevent duplicate fulfillment metadata and Segment events.
- Add coverage for recovery and error propagation.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
commerce_coordinator/apps/commercetools/tests/test_stripe_payment_finalize.py |
Tests recovery and error propagation scenarios. |
commerce_coordinator/apps/commercetools/stripe_payment_finalize.py |
Implements existing-order recovery and shared healing. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
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.
Summary
Order Completedevent when that existing order is found. If the lookup itself fails in CommerceTools, let Celery retry that error instead of hiding it behind the original create error.What Was Built
finalize_ct_order_from_stripe_picreate_order_from_cartraisesCommercetoolsError, queryget_order_by_payment_idagainalready_existed=Truewith no Segment eventValueError(no order) re-raises the original create error so bounded retries / recovery logging still applyCommercetoolsErrorpropagates so Celery retries the lookup failureTest Plan
track,already_existed=TrueCommercetoolsError→ lookup error propagates/payment-return+payment_intent.succeeded→ one CT order, one Charge txn, one Segment eventNFR Compliance
quarantine,pi_id,ct_payment_id,ct_cart_id,reason,source).