Skip to content

Skip HubSpot deal sync for program-enrolled courses - #3844

Merged
cp-at-mit merged 3 commits into
mainfrom
hubspot-no-deal-created-for-courses-in-program
Aug 12, 2026
Merged

Skip HubSpot deal sync for program-enrolled courses#3844
cp-at-mit merged 3 commits into
mainfrom
hubspot-no-deal-created-for-courses-in-program

Conversation

@cp-at-mit

Copy link
Copy Markdown
Contributor

What are the relevant tickets?

NA

Description (What does it do?)

Add a check in sync_hubspot_deal to skip syncing orders where the purchaser is already enrolled in a program containing the purchased course run. This prevents duplicate/misleading deals in HubSpot when a user buys an individual course that's part of a program they're already enrolled in.

How can this be tested?

  • Enroll into a program and pay for it
  • Enroll into one of the courses in the program
  • Verify that no deal is created for the course enrollment but a deal is created for the program purchase.

Add a check in sync_hubspot_deal to skip syncing orders where the purchaser is already enrolled in a program containing the purchased course run. This prevents duplicate/misleading deals in HubSpot when a user buys an individual course that's part of a program they're already enrolled in.
@github-actions

Copy link
Copy Markdown

OpenAPI Changes

Show/hide changes
## Changes for v0.yaml:
No changes detected

## Changes for v1.yaml:
No changes detected

## Changes for v2.yaml:
No changes detected

Unexpected changes? Ensure your branch is up-to-date with main (consider rebasing).

@cp-at-mit
cp-at-mit marked this pull request as ready for review August 11, 2026 17:16
@dsubak
dsubak self-requested a review August 12, 2026 13:33
Comment thread hubspot_sync/task_helpers.py Outdated

def _order_is_for_program_enrolled_course(order: Order) -> bool:
"""Return True if any line is a course run belonging to a program the purchaser is already enrolled in."""
for line in order.lines.all():

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I'm a bit hazy on the data model so forgive me if this is a bad question - generally speaking, how many line items do we expect to have per order?

As written, this could execute up to one query per course run line item. If we do have orders w/ large numbers of line items I'm wondering it's worth iterating through line items to gather the list of CourseRuns from the order and then running a single ProgramEnrollment query for all courses on the order. That'd mean we only do one query regardless of the number of course run line items.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

So I think right now we only support a single line item being added by the user, but we might as well make this efficient like you're saying in case that requirement changes.

Reduce redundant queries when checking whether an order includes a course run from a program the purchaser is already enrolled in. The helper now gathers purchased course IDs first and performs a single `ProgramEnrollment` lookup instead of checking each order line individually.
@cp-at-mit
cp-at-mit merged commit 68e19f7 into main Aug 12, 2026
13 checks passed
@cp-at-mit
cp-at-mit deleted the hubspot-no-deal-created-for-courses-in-program branch August 12, 2026 19:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants