Skip to content

Commit d519430

Browse files
fix(hubspot): restore logic for updating orgid_unique property (#6044)
1 parent 592a353 commit d519430

3 files changed

Lines changed: 36 additions & 12 deletions

File tree

api/integrations/lead_tracking/hubspot/client.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,12 +222,15 @@ def update_company(
222222
hubspot_company_id: str,
223223
name: str | None = None,
224224
active_subscription: str | None = None,
225+
flagsmith_organisation_id: int | None = None,
225226
) -> dict[str, Any]:
226227
properties = {}
227228
if name is not None:
228229
properties["name"] = name
229230
if active_subscription is not None:
230231
properties["active_subscription"] = active_subscription
232+
if flagsmith_organisation_id is not None:
233+
properties["orgid_unique"] = str(flagsmith_organisation_id)
231234

232235
simple_public_object_input = SimplePublicObjectInput(properties=properties)
233236

api/integrations/lead_tracking/hubspot/lead_tracker.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -162,13 +162,13 @@ def _get_organisation_hubspot_id(
162162
return None
163163
org_hubspot_id: str = company["id"]
164164

165-
properties = company.get("properties", {})
166-
existing_name = properties.get("name")
167-
if existing_name != organisation.name:
168-
self.client.update_company(
169-
name=organisation.name,
170-
hubspot_company_id=org_hubspot_id,
171-
)
165+
# Update the company in Hubspot with the name of the created
166+
# organisation in Flagsmith, and its numeric ID.
167+
self.client.update_company(
168+
name=organisation.name,
169+
hubspot_company_id=org_hubspot_id,
170+
flagsmith_organisation_id=organisation.id,
171+
)
172172

173173
# Store the organisation data in the database since we are
174174
# unable to look them up via a unique identifier.

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

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -286,13 +286,34 @@ def test_associate_contact_to_company_succeeds(hubspot_client: HubspotClient) ->
286286
@pytest.mark.parametrize(
287287
"kwargs, expected_properties",
288288
[
289-
({"name": "Test Organisation"}, {"name": "Test Organisation"}),
290289
(
291-
{"name": "Test Organisation", "active_subscription": "scaleup"},
292-
{"name": "Test Organisation", "active_subscription": "scaleup"},
290+
{"name": "Test Organisation", "flagsmith_organisation_id": 1},
291+
{"name": "Test Organisation", "orgid_unique": "1"},
292+
),
293+
(
294+
{
295+
"name": "Test Organisation",
296+
"active_subscription": "scaleup",
297+
"flagsmith_organisation_id": 1,
298+
},
299+
{
300+
"name": "Test Organisation",
301+
"active_subscription": "scaleup",
302+
"orgid_unique": "1",
303+
},
304+
),
305+
(
306+
{"active_subscription": "scaleup", "flagsmith_organisation_id": 1},
307+
{"active_subscription": "scaleup", "orgid_unique": "1"},
308+
),
309+
(
310+
{
311+
"name": None,
312+
"active_subscription": None,
313+
"flagsmith_organisation_id": None,
314+
},
315+
{},
293316
),
294-
({"active_subscription": "scaleup"}, {"active_subscription": "scaleup"}),
295-
({"name": None, "active_subscription": None}, {}),
296317
],
297318
)
298319
def test_update_company_calls_hubspot_api(

0 commit comments

Comments
 (0)