Skip to content

fix(dimensional): platform-scope MicroMasters program_fk lookup in tfact_enrollment#2412

Open
blarghmatey wants to merge 1 commit into
mainfrom
fix/tfact-enrollment-program-fk-platform-scoping
Open

fix(dimensional): platform-scope MicroMasters program_fk lookup in tfact_enrollment#2412
blarghmatey wants to merge 1 commit into
mainfrom
fix/tfact-enrollment-program-fk-platform-scoping

Conversation

@blarghmatey

Copy link
Copy Markdown
Member

What are the relevant tickets?

Closes #2378

Description (What does it do?)

tfact_enrollment.sql's micromasters_program_lookup CTE enriched course-scope enrollments with a MicroMasters program_fk by joining on courserun_readable_id alone, with no platform constraint. That meant:

  • Any platform's enrollment sharing a MM-linked courserun_readable_id (not just the edxorg/mitxonline enrollments that MM courses actually run on) could inherit a MicroMasters program_fk.
  • A course run reused across two different MicroMasters programs would fan out the left join, silently masked by the model's final defensive dedup (which just picks an arbitrary winning row).
  • _fact_tables.yml documented program_fk as null for course enrollments except the mitxpro program-purchase case, contradicting the MM enrichment behavior the code already relied on.

Fix:

  • Platform-scope the lookup by carrying the enrollment's own platform value (mapped from the source edX.org/MITx Online strings to the edxorg/mitxonline codes used elsewhere in the model) and joining on (courserun_readable_id, platform) instead of courserun_readable_id alone.
  • Dedupe micromasters_program_lookup to one row per (courserun_readable_id, platform) via row_number() (Trino has no QUALIFY, consistent with the existing dedup pattern later in the same model) so a course run belonging to two MM programs can't fan out the enrollment it's joined against.
  • Updated the program_fk column description in _fact_tables.yml to document the MicroMasters enrichment path.

How can this be tested?

  • dbt parse and dbt compile -s tfact_enrollment both succeed against the local duckdb target; the compiled SQL confirms the Jinja var() calls resolve to the correct source platform strings (edX.org, MITx Online) used in the case mapping.
  • Existing relationships test on program_fkdim_program.program_pk and the dbt_utils.unique_combination_of_columns test on (enrollment_id, platform, enrollment_type) continue to guard the model's grain; a full run against the QA warehouse is recommended before merge to confirm no unexpected program_fk population changes for edge-case platforms.

Additional Context

Found via the dbt warehouse semantic-accuracy audit (dimensional-layer correctness epic). Related identity-collapse issue in the same audit: MicroMasters certificates in tfact_certificate also dual-source from edxorg with a separate defensive-dedup gap (not addressed by this PR).

Copilot AI review requested due to automatic review settings July 9, 2026 12:06

Copilot AI left a comment

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.

Pull request overview

This PR fixes a dimensional-layer correctness issue in tfact_enrollment where MicroMasters program_fk enrichment could leak across platforms by joining on courserun_readable_id alone. It aligns the model behavior with the platform-pairing rule described in the issue/PR description and updates the schema docs to reflect the intended enrichment behavior.

Changes:

  • Platform-scopes the MicroMasters program lookup by joining on (courserun_readable_id, platform) rather than courserun_readable_id alone.
  • Pre-dedupes the MicroMasters lookup to a single row per (courserun_readable_id, platform) using row_number() (Trino-compatible pattern).
  • Updates _fact_tables.yml documentation for program_fk to include the MicroMasters enrichment behavior for edxorg/mitxonline course enrollments.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
src/ol_dbt/models/dimensional/tfact_enrollment.sql Adds platform-aware MicroMasters lookup + Trino-friendly pre-dedup and joins it on both courserun and platform to prevent cross-platform leakage/fanout.
src/ol_dbt/models/dimensional/_fact_tables.yml Updates program_fk column documentation to reflect MicroMasters-based population for edxorg/mitxonline course enrollments.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@blarghmatey
blarghmatey force-pushed the fix/tfact-enrollment-program-fk-platform-scoping branch from c2e6da6 to e3393e5 Compare July 11, 2026 00:55
@github-actions

Copy link
Copy Markdown

🔎 ol-dbt impact — column-level blast radius

✅ No column-level downstream impact detected for the changed models.

Posted by ol-dbt impact (annotate-only — does not block merge).

…act_enrollment

micromasters_program_lookup joined enrollments_with_fks on courserun_readable_id
alone, so any platform's enrollment sharing that readable_id (not just the
edxorg/mitxonline enrollments MM courses are actually hosted on) could inherit
a MicroMasters program_fk, and a course run reused across two MM programs
would fan out the join undetected. Platform-scope the join using the
enrollments' own platform values, and dedupe to one row per
(courserun_readable_id, platform).

_fact_tables.yml documented program_fk as null for course enrollments except
the mitxpro program-purchase case, silently omitting the MM enrichment path
the code already relied on — document it.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@blarghmatey
blarghmatey force-pushed the fix/tfact-enrollment-program-fk-platform-scoping branch from e3393e5 to 1fbb2f3 Compare July 16, 2026 14:06
@blarghmatey
blarghmatey requested a review from rachellougee July 16, 2026 17:50

@rachellougee rachellougee left a comment

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.

LGTM. The changes are mostly preventive/defensive - I verified against production: no enrollment currently has a cross-platform MM program_fk, and no course run currently maps to two MM programs. So no full refresh needed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Fix tfact_enrollment.program_fk platform-scoping violation and doc contradiction

3 participants