A failed HubSpot write stops the sync and reports the orphaned contacts 🟩

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
Daniel Roth 2026-07-06 13:35:47 +00:00
parent 065217f8af
commit 81d25caead

View file

@ -3,6 +3,7 @@ from typing import Dict, List, Optional, Tuple, Union
from domain.abri.models import AbriRequestRejected, PlaceRef, Tenant
from etl.hubspot.deal_contacts_client import HubspotDealContactsClient
from etl.hubspot.errors import HubspotRequestError
from infrastructure.abri.abri_client import AbriClient
@ -106,12 +107,27 @@ class TenantDataSyncOrchestrator:
return tenancy
contact_ids: List[str] = []
for tenant in tenancy.tenants:
contact_id = self._hubspot.create_contact(_contact_properties(tenant))
self._hubspot.associate_contact_to_deal(
deal_id=deal_id, contact_id=contact_id
)
contact_ids.append(contact_id)
associated_ids: List[str] = []
for tenant_index, tenant in enumerate(tenancy.tenants):
try:
contact_id = self._hubspot.create_contact(
_contact_properties(tenant)
)
contact_ids.append(contact_id)
self._hubspot.associate_contact_to_deal(
deal_id=deal_id, contact_id=contact_id
)
associated_ids.append(contact_id)
except HubspotRequestError as error:
# Fail fast at the first failed write; `error` is already
# scrubbed, so chaining it keeps tracebacks PII-free.
raise TenantDataSyncError(
message=str(error),
deal_id=deal_id,
tenant_index=tenant_index,
contact_ids_created=tuple(contact_ids),
contact_ids_associated=tuple(associated_ids),
) from error
return TenantDataSyncSummary(
tenancy_reference=tenancy.tenancy_reference,