Skip to content

fix: call revoke_line_items_task directly instead of via signal - #542

Open
bseverino wants to merge 2 commits into
mainfrom
bseverino/RV2U-473-fix-entitlement-task
Open

fix: call revoke_line_items_task directly instead of via signal#542
bseverino wants to merge 2 commits into
mainfrom
bseverino/RV2U-473-fix-entitlement-task

Conversation

@bseverino

Copy link
Copy Markdown
Member

fulfill_order_returned_signal_task was using send_robust() on a Django signal (fulfill_order_returned_send_revoke_line_items_signal) to trigger revoke_line_items_task. This required the signal to be wired in CC_SIGNALS, which could be silently overridden by the production YAML config (vars().update(config_from_yaml) in production.py). When send_robust() has zero connected receivers, it returns an empty list without raising -- so the failure was completely silent.

Changes made across 6 files:

  1. sub_messages/tasks.py -- Replaced fulfill_order_returned_send_revoke_line_items_signal.send_robust(...) with a direct call to revoke_line_items_task.delay(order_id=order_id, return_items=return_items). This eliminates the fragile signal indirection since both the caller and callee are within the same app.
  2. signals.py -- Removed the fulfill_order_returned_send_revoke_line_items_signal definition (no longer needed). The revoke_line_items receiver function remains available.
  3. settings/base.py -- Removed the fulfill_order_returned_send_revoke_line_items_signal entry from CC_SIGNALS.
  4. tests/sub_messages/test_tasks.py -- Updated both OrderReturnedMessageSignalTaskTests and FulfillOrderReturnedSignalTaskTests to mock revoke_line_items_task instead of send_robust, and assert on .delay() calls.
  5. tests/test_signals.py -- Updated RevokeLineItemsTest to use example_signal instead of the deleted signal, and removed the unused import.
  6. settings/test.py -- Added missing signal entries (entitlement, PayPal, IAP/mobile) to keep CC_SIGNALS in sync with base.py.

Internal ticket: https://redventures.atlassian.net/browse/RV2U-473

The revoke task was wired through a Django signal
(fulfill_order_returned_send_revoke_line_items_signal) that required
CC_SIGNALS configuration. In production the YAML config overrides
CC_SIGNALS, and the new signal entry was missing, so send_robust()
silently dispatched to zero receivers and the task was never enqueued.

Replace the signal indirection with a direct .delay() call since both
the caller and callee live in the same app. Also sync test.py
CC_SIGNALS with base.py for other missing entries.

Co-authored-by: Cursor <cursoragent@cursor.com>
@bseverino
bseverino requested a review from a team as a code owner May 13, 2026 21:12
Copilot AI review requested due to automatic review settings May 13, 2026 21:12

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Replaces an indirect signal dispatch (fulfill_order_returned_send_revoke_line_items_signal.send_robust(...)) with a direct Celery task invocation (revoke_line_items_task.delay(...)) to eliminate a silent failure mode where production YAML config could override CC_SIGNALS and leave the signal with zero receivers. The signal definition, its CC_SIGNALS entry, and related test wiring are removed/updated accordingly, and settings/test.py is brought back in sync with settings/base.py.

Changes:

  • Replace signal send_robust with direct revoke_line_items_task.delay call in sub_messages/tasks.py; drop the now-unused signal definition and its CC_SIGNALS entry.
  • Update task tests to mock revoke_line_items_task and assert on .delay(...) calls; switch RevokeLineItemsTest to fire via example_signal.
  • Add missing entitlement, PayPal, and IAP/mobile signal entries to settings/test.py to match settings/base.py.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated no comments.

Show a summary per file
File Description
commerce_coordinator/apps/commercetools/sub_messages/tasks.py Replace signal send with direct revoke_line_items_task.delay(...) and update imports.
commerce_coordinator/apps/commercetools/signals.py Remove the unused fulfill_order_returned_send_revoke_line_items_signal definition.
commerce_coordinator/settings/base.py Remove the corresponding CC_SIGNALS entry.
commerce_coordinator/settings/test.py Add missing entitlement/PayPal/IAP signal entries to align with base.py.
commerce_coordinator/apps/commercetools/tests/sub_messages/test_tasks.py Mock revoke_line_items_task and assert on .delay(...) instead of send_robust.
commerce_coordinator/apps/commercetools/tests/test_signals.py Drop unused import; use example_signal to test the revoke_line_items receiver.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Co-authored-by: Cursor <cursoragent@cursor.com>
@bseverino
bseverino force-pushed the bseverino/RV2U-473-fix-entitlement-task branch from 4e9a802 to d9cd12e Compare May 14, 2026 13:59
@github-actions

Copy link
Copy Markdown

Coverage report

Click to see where and how coverage changed

FileStatementsMissingCoverageCoverage
(new stmts)
Lines missing
  commerce_coordinator/apps/commercetools
  signals.py
  commerce_coordinator/apps/commercetools/sub_messages
  tasks.py
  commerce_coordinator/apps/commercetools/tests
  test_signals.py
  commerce_coordinator/apps/commercetools/tests/sub_messages
  test_tasks.py
Project Total  

This report was generated by python-coverage-comment-action

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