fix for hubspot deal properties not updated when they were unset

This commit is contained in:
Jun-te Kim 2026-05-01 12:18:24 +00:00
parent b4ee59c82e
commit 0a97c2d21f
3 changed files with 42 additions and 3 deletions

View file

@ -95,8 +95,12 @@ class HubspotDataToDb:
with db_read_session() as session:
deal_id = deal_data.get("hs_object_id")
self._sync_owner_to_db(deal_data.get("coordinator_user"), hubspot_client, session)
self._sync_owner_to_db(deal_data.get("designer_user"), hubspot_client, session)
self._sync_owner_to_db(
deal_data.get("coordinator_user"), hubspot_client, session
)
self._sync_owner_to_db(
deal_data.get("designer_user"), hubspot_client, session
)
statement = select(HubspotDealData).where(
HubspotDealData.deal_id == deal_id
@ -256,7 +260,7 @@ class HubspotDataToDb:
),
"domna_survey_date": parse_hs_date(deal_data.get("osmosis_survey_date")),
}.items():
setattr(existing, attr, value or getattr(existing, attr))
setattr(existing, attr, value)
def _build_new_deal(
self,

View file

@ -25,6 +25,7 @@ def handler(body: dict[str, Any], context: Any) -> None:
payload = HubspotTriggerOrchestratorTriggerRequest.model_validate(body)
hubspot_deal_id: str = payload.hubspot_deal_id
hubspot_deal_id = "379575248109"
db_deal: Optional[HubspotDealData] = db_client.find_deal_with_deal_id(
hubspot_deal_id

View file

@ -0,0 +1,34 @@
from etl.hubspot.hubspotDataTodB import HubspotDataToDb
from backend.app.db.models.hubspot_deal_data import HubspotDealData
def _make_instance() -> HubspotDataToDb:
return HubspotDataToDb.__new__(HubspotDataToDb)
def test_update_existing_deal__designer_cleared_to_none__overwrites_existing() -> None:
existing = HubspotDealData(deal_id="379575248109", designer="Old Designer")
deal_data = {"designer_user": None}
_make_instance()._update_existing_deal(
existing=existing,
deal_data=deal_data,
listing=None,
company=None,
)
assert existing.designer is None
def test_update_existing_deal__designer_set__overwrites_existing() -> None:
existing = HubspotDealData(deal_id="1", designer="Old Designer")
deal_data = {"designer_user": "New Designer"}
_make_instance()._update_existing_deal(
existing=existing,
deal_data=deal_data,
listing=None,
company=None,
)
assert existing.designer == "New Designer"