diff --git a/applications/abri/dispatch.py b/applications/abri/dispatch.py index 092c0a59c..2362fa1d0 100644 --- a/applications/abri/dispatch.py +++ b/applications/abri/dispatch.py @@ -99,6 +99,10 @@ def dispatch_abri_flows( def _run_amend(request: AbriTriggerRequest, flows: AbriFlows) -> str: + if request.client_booking_reference is None: + raise DealDivergedFromAbriError( + flow="amend_job", deal_id=request.hubspot_deal_id + ) if ( request.confirmed_survey_date is None or request.third_party_surveyor_identifier is None @@ -165,8 +169,13 @@ def _run_log( def _run_abandon(request: AbriTriggerRequest, flows: AbriFlows) -> str: # Runs last so a cancellation can never interfere with a log, amend or - # tenant sync in the same batch. A missing job_no raises the retriable - # not-yet-recorded error, which propagates so the task fails and redelivers. + # tenant sync in the same batch. With a Job Number, a missing DB job_no + # raises the retriable not-yet-recorded error, which propagates so the task + # fails and redelivers; with no Job Number at all, the deal has diverged. + if request.client_booking_reference is None: + raise DealDivergedFromAbriError( + flow="abandon_job", deal_id=request.hubspot_deal_id + ) outcome = flows.abandon_job( DealAbandonment( deal_id=request.hubspot_deal_id,