Skip to content

Commit 123b18d

Browse files
Holmusclaude
andcommitted
fix(Integrations): Stop overwriting HubSpot company names with Flagsmith org names
When a user signs up, the HubSpot integration overwrites the company name with whatever the user typed as their Flagsmith org name. This leads to incorrect names replacing real company names that HubSpot already enriched from the email domain. Now only sets the company name if HubSpot doesn't already have one, using the email domain as a fallback instead of the org name. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent b4cf014 commit 123b18d

2 files changed

Lines changed: 8 additions & 7 deletions

File tree

api/integrations/lead_tracking/hubspot/lead_tracker.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -158,18 +158,19 @@ def _get_organisation_hubspot_id(
158158
company_kwargs["organisation_id"] = organisation.id
159159
company_kwargs["active_subscription"] = organisation.subscription.plan
160160

161-
# As Hubspot creates/associates companies automatically based on contact domain
162-
# we need to get the hubspot id when this user creates the company for the first time
163-
# and update the company name
161+
# HubSpot auto-creates companies from contact email domains and may
162+
# enrich them with the correct company name. We look up the company
163+
# by domain and only set the name if HubSpot doesn't already have one,
164+
# using the email domain as a fallback rather than the Flagsmith org
165+
# name (which is often a placeholder like "test" or "ew").
164166
company = self._get_hubspot_company_by_domain(domain)
165167
if not company:
166168
return None
167169
org_hubspot_id: str = company["id"]
168170

169-
# Update the company in Hubspot with the name of the created
170-
# organisation in Flagsmith, and its numeric ID.
171+
existing_name = company.get("properties", {}).get("name")
171172
self.client.update_company(
172-
name=organisation.name,
173+
name=domain if not existing_name else None,
173174
hubspot_company_id=org_hubspot_id,
174175
flagsmith_organisation_id=organisation.id,
175176
)

api/tests/unit/integrations/lead_tracking/hubspot/test_unit_hubspot_lead_tracking.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ def test_track_hubspot_lead_v2__new_user_added_to_org__creates_associations(
151151
}
152152
mock_client_existing_contact.update_company.return_value = {
153153
"id": HUBSPOT_COMPANY_ID,
154-
"properties": {"name": organisation.name},
154+
"properties": {"name": domain}, # name preserved, not overwritten
155155
}
156156
assert getattr(organisation, "hubspot_organisation", None) is None
157157
# When

0 commit comments

Comments
 (0)