Skip to content

fix: delivery webhook respects order status transitions - #83

Merged
lordlabakdas merged 1 commit into
masterfrom
fix/delivery-webhook-respects-status-transitions
Oct 4, 2026
Merged

lordlabakdas merged 1 commit into
masterfrom
fix/delivery-webhook-respects-status-transitions

Conversation

@lordlabakdas

Copy link
Copy Markdown
Owner

Summary

Follow-up to #82. DeliveryService.apply_webhook_update() wrote order.status = "delivered" directly, bypassing update_order_status()'s ORDER_STATUS_TRANSITIONS check entirely — it's a different code path (webhook ingestion, not the store-authenticated PUT /{order_id}/status endpoint).

That meant a late/stale webhook arriving after a store already cancelled the order (which now restocks inventory and reverses loyalty points, per #82) could silently flip the order back to "delivered" — with none of that cancellation's side effects undone. Stock and loyalty balances would desync from the order's real state.

Webhook-driven delivery confirmation now only advances Order.status when "delivered" is a legal next state per ORDER_STATUS_TRANSITIONS (normally ready → delivered); otherwise it logs a warning and leaves the order alone. The Delivery row itself still records the vendor's "delivered" status regardless — only the Order.status write is guarded.

Test plan

  • New unit test: webhook reporting delivered for a cancelled order does not resurrect it (tests/unit/test_delivery_service.py)
  • Existing test_apply_webhook_update_marks_order_delivered updated to start from a legal "ready" status
  • pytest tests/ -v — 611/611 pass

🤖 Generated with Claude Code

https://claude.ai/code/session_014t1eBFvEm5tiPyqQiQ3DNM

apply_webhook_update() wrote order.status = "delivered" directly,
bypassing update_order_status()'s ORDER_STATUS_TRANSITIONS check added
in #82. A late/stale webhook arriving after a store already cancelled
the order (which restocks inventory and reverses loyalty points) could
silently flip it back to "delivered" with none of that reversed —
leaving stock and loyalty balances desynced from the order's real
state.

Webhook-driven delivery confirmation now only advances the order when
that transition is legal (normally ready -> delivered); otherwise it
logs a warning and leaves the order's status alone. The Delivery row
itself still records the vendor's "delivered" status either way — only
the Order's status write is guarded.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_014t1eBFvEm5tiPyqQiQ3DNM
@lordlabakdas
lordlabakdas merged commit 79ff430 into master Oct 4, 2026
6 checks passed
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.

1 participant