Skip to content

fix: rely-solely-on-hubspot-to-create-organisations #5739

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Jul 16, 2025

Conversation

Zaimwa9
Copy link
Contributor

@Zaimwa9 Zaimwa9 commented Jul 9, 2025

Thanks for submitting a PR! Please check the boxes below:

  • I have added information to docs/ if required so people know about the feature!
  • I have filled in the "Changes" section below?
  • I have filled in the "How did you test this code" section below?
  • I have used a Conventional Commit title for this Pull Request

Changes

Hubspot does warn about XX seconds delay between a record is created and it's availability in their search API. It has created duplicates because on our side, we trigger create_lead that:

  • Get hubspot_contact_id and sync our DB if not exists
  • Get hubspot_org_id and sync our DB if not exists
  • Used to create the company in hubspot if not found This part is to be removed to trust hubspot association

Also #5711 should reduce this case from happening by adding a delay before triggering create_lead

This PR aims to remove the fallback of creating the organisation in hubspot if we couldn't find it by domain

How did you test this code?

  • Updated tests

@Zaimwa9 Zaimwa9 requested a review from a team as a code owner July 9, 2025 14:13
@Zaimwa9 Zaimwa9 requested review from khvn26 and removed request for a team July 9, 2025 14:13
@github-actions github-actions bot added the api Issue related to the REST API label Jul 9, 2025
Copy link

vercel bot commented Jul 9, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
docs ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jul 15, 2025 7:23am
flagsmith-frontend-preview ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jul 15, 2025 7:23am
flagsmith-frontend-staging ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jul 15, 2025 7:23am

@github-actions github-actions bot added the fix label Jul 9, 2025
Copy link
Contributor

github-actions bot commented Jul 9, 2025

Docker builds report

Image Build Status Security report
ghcr.io/flagsmith/flagsmith-api-test:pr-5739 Finished ✅ Skipped
ghcr.io/flagsmith/flagsmith-e2e:pr-5739 Finished ✅ Skipped
ghcr.io/flagsmith/flagsmith-frontend:pr-5739 Finished ✅ Results
ghcr.io/flagsmith/flagsmith-api:pr-5739 Finished ✅ Results
ghcr.io/flagsmith/flagsmith-private-cloud:pr-5739 Finished ✅ Results

@Zaimwa9 Zaimwa9 requested a review from emyller July 10, 2025 07:29
Copy link

codecov bot commented Jul 10, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 97.77%. Comparing base (58bdf04) to head (3fac3b6).
Report is 10 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #5739   +/-   ##
=======================================
  Coverage   97.77%   97.77%           
=======================================
  Files        1255     1255           
  Lines       44357    44357           
=======================================
  Hits        43371    43371           
  Misses        986      986           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Comment on lines +163 to +164
if not company:
return None
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How can a company not exist in Hubspot at this point? When it happens, what should we do?

Copy link
Contributor Author

@Zaimwa9 Zaimwa9 Jul 11, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a small indexation delay. Duplicated companies has been observed empirically and a case happened last week (I can share offline if you are interested).
With hubspot creating/associating under the hood the contact with the company. And this logic getting executed within 10 seconds => company not available from their API.
doc.
It may take a few moments for newly created or updated CRM objects to appear in search results.

So conclusion discussed with Uriel is to let it go, not have action on our side and rely only on hubspot engine. It's acceptable that our DB doesn't reflect 100% hubspot in similar cases

More details
Unique/clean data in hubspot > Our DB synchronization because before any update in hubspot (especially update_active_subscription) we:

  1. Check HubspotOrganisation
  2. If not synchronized get_company_by_domain and create HubspotOrganisation for next time (and obviously in those later steps it should be available)

We don't make so much use of the hubspot_organisation_id besides those operations.

Last thing, in this one, there is an additional 2 (or 3) minutes buffer before triggering this logic, that should mitigate the risks of not finding the record

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Gotcha, thank you for the explanation.

Couple things, if letting go is indeed the business decision here:

  1. Let's add a comment so this return None isn't prone to the reader's imagination. 😅
  2. Question: can letting go possibly lead to inconsistencies in the CRM layer?

@github-actions github-actions bot added fix and removed fix labels Jul 11, 2025
@github-actions github-actions bot added fix and removed fix labels Jul 11, 2025
@github-actions github-actions bot added fix and removed fix labels Jul 11, 2025
@Zaimwa9 Zaimwa9 requested a review from emyller July 14, 2025 12:56
@Zaimwa9 Zaimwa9 requested a review from emyller July 14, 2025 16:59
@github-actions github-actions bot added fix and removed fix labels Jul 14, 2025
Copy link
Contributor

@matthewelwell matthewelwell left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approving based on conversations with @emyller and @Zaimwa9 similar to the comment left on #5711

@Zaimwa9 Zaimwa9 merged commit 4b676b5 into main Jul 16, 2025
42 of 43 checks passed
@Zaimwa9 Zaimwa9 deleted the fix/prevent-hubspot-company-creation-in-association branch July 16, 2025 09:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api Issue related to the REST API fix
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants