diff --git a/etl/hubspot/hubspotDataTodB.py b/etl/hubspot/hubspotDataTodB.py index b63f6d28..278fbe43 100644 --- a/etl/hubspot/hubspotDataTodB.py +++ b/etl/hubspot/hubspotDataTodB.py @@ -95,15 +95,8 @@ class HubspotDataToDb: with db_read_session() as session: deal_id = deal_data.get("hs_object_id") - resolved_deal_data = { - **deal_data, - "coordinator_user": self._resolve_owner_name( - deal_data.get("coordinator_user"), hubspot_client, session - ), - "designer_user": self._resolve_owner_name( - 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 @@ -114,7 +107,7 @@ class HubspotDataToDb: self._handle_existing_photo_upload(existing, hubspot_client) print(f"🔄 Updating existing deal (deal_id={deal_id})") - self._update_existing_deal(existing, resolved_deal_data, listing, company) + self._update_existing_deal(existing, deal_data, listing, company) session.add(existing) session.commit() @@ -124,7 +117,7 @@ class HubspotDataToDb: else: print(f"🆕 Inserting new deal (deal_id={deal_id})") new_record: HubspotDealData = self._build_new_deal( - deal_id, resolved_deal_data, listing, company + deal_id, deal_data, listing, company ) # Handle upload at insert time @@ -135,24 +128,21 @@ class HubspotDataToDb: session.refresh(new_record) return new_record - def _resolve_owner_name( + def _sync_owner_to_db( self, owner_id: Optional[str], hubspot_client: HubspotClient, session: Session, - ) -> Optional[str]: + ) -> None: if not owner_id: - return None + return - existing: Optional[HubspotUser] = session.get(HubspotUser, owner_id) owner_info = hubspot_client.get_owner_info(owner_id) - if owner_info is None: - if existing: - return f"{existing.first_name or ''} {existing.last_name or ''}".strip() or None - return None + return now = datetime.now(timezone.utc) + existing: Optional[HubspotUser] = session.get(HubspotUser, owner_id) if existing: existing.first_name = owner_info["first_name"] existing.last_name = owner_info["last_name"] @@ -170,10 +160,6 @@ class HubspotDataToDb: ) ) - first = owner_info["first_name"] or "" - last = owner_info["last_name"] or "" - return f"{first} {last}".strip() or None - def _update_existing_deal( self, existing: HubspotDealData,