Skip to content

Investigate conditional uniqueness logic in marts__combined_program_enrollment_detail and downstream reporting models #1957

Open

Description

@quazi-h

While working on adding a new reporting model (program_enrollment_with_user_report), we discovered some differences in the uniqueness tests between marts__combined_program_enrollment_detail and the upstream models used to build that model.

The marts__combined_program_enrollment_detail mart model and its downstream reporting models use conditional uniqueness tests with platform-specific logic that may indicate underlying data quality issues or overly complex grain definitions. This creates maintenance burden and weakens data integrity validation.

Please investigate why marts__combined_program_enrollment_detail needs conditional uniqueness tests and whether the upstream model should be fixed.

Expected Behavior

The two models should have the same logic in the dbt tests for uniqueness.

Current Behavior

Current State:

Two separate uniqueness tests with mutually exclusive row_condition filters
Hard-coded exception for program_id = 2 (edX.org programs)
Different grain definitions for different platforms within the same model

For non-edX.org programs (program_id !=2):

uniqueness: [program_title, user_username, platform_name, programenrollment_created_on]

For edX.org programs (program_id =2):

uniqueness: [user_username, user_email]

Using the same logic for the uniqueness tests causes the reporting model to fail.
19:50:13 Failure in test dbt_expectations_expect_compound_columns_to_be_unique_program_enrollment_with_user_report_platform_name__program_id__user_username__user_email__programenrollment_created_on (models/reporting/_reporting__models.yml) 19:50:13  Got 1870062 results, configured to fail if >10

Steps to Reproduce

dbt build --select program_enrollment_with_user_report --vars 'schema_suffix: <your_username>' --target dev_production

Possible Solution (Generated by AI, may need to be revised)

Understand the Business Requirements
Interview stakeholders: Why do edX.org enrollments behave differently?
Understand re-enrollment scenarios across all platforms
Determine if programenrollment_created_on should always be part of uniqueness
Identify if there's a true unique identifier we're missing (e.g., enrollment UUID)

Analyze the Data
Query edX.org program enrollments to identify actual duplicate patterns
Check if duplicates exist only for re-enrolled users or across all users
Verify if user_username + user_email is truly unique for edX.org
Compare duplication rates across platforms

Review Upstream Sources
Check source system documentation for edX.org program enrollment grain
Review ETL logic in stg__edxorg__* models for enrollment handling
Identify if duplicates are introduced during staging or marts layer

Evaluate Alternatives
Option A: Add enrollment_id or similar unique identifier to all platforms
Option B: Standardize re-enrollment handling (e.g., is_current_enrollment flag)
Option C: Use qualified grain (most recent enrollment per user-program)
Option D: Accept conditional logic but document extensively with business rationale

Success Criteria
At minimum, this investigation should result in:
Documentation: Clear explanation of why conditional uniqueness tests exist and whether they're correct by design or masking data issues
One of the following outcomes:
Simplification: Replace conditional tests with a single comprehensive uniqueness test
Standardization: Add proper unique identifiers to eliminate need for conditional logic
Acceptance: Keep conditional tests but add thorough business logic documentation
Downstream Impact: Update all affected reporting models with findings

Activity

  1. added theissue type on Mar 4, 2026
  2. blarghmatey commented on Apr 6, 2026

    @blarghmatey
    Member

    Update in light of the dimensional model work:

    The conditional uniqueness tests and fragile grain in marts__combined_program_enrollment_detail are a symptom of building complex aggregations directly on intermediate models. The long-term resolution is to migrate this mart to use the dimensional layer:

    • tfact_enrollment already has a clean, well-defined grain of one row per enrollment event, with per-platform watermarks
    • dim_program and bridge_program_course provide the program-course mapping
    • dim_user provides the user dimension with a stable surrogate key

    Migration tracked in: #2083 (Migrate marts__combined_program_enrollment_detail to use dimensional layer), which is part of epic #2072.

    The investigation requested in this bug is still valuable to understand whether the conditional uniqueness reflects a real data quality issue in the source or just an artifact of the mart's construction. The findings should inform what validation tests are added to tfact_enrollment when the migration happens.

  3. blarghmatey commented on Jul 6, 2026

    @blarghmatey
    Member

    2026-07 warehouse audit — additional findings (epic #2375)

    The audit confirms this is one instance of a broader fan-out defect family, and found two more un-deduped joins in the same engagement lineage feeding the live "Course Engagement" dashboard (P0):

    1. Missing user dedup on event marts. marts__combined_course_engagements.sql:165-176 dedupes int__combined__users with row_number() over (partition by user_username, platform) — proving duplicates exist — but marts__combined_problem_submissions.sql:69-72,102-105 and marts__combined_video_engagements.sql:73-76,120-123 left-join the same model with no dedup, duplicating event rows for any duplicated user.
    2. Missing platform in daily-activity join. marts__combined_course_engagements.sql:257-272 joins the three daily-activity CTEs on (date, courserun_readable_id, user_username) without platform, so cross-platform username collisions double-count num_problem_submitted / num_video_played / num_discussion_participated.

    Recommended fix: dedupe in int__combined__users itself (the root cause) and add platform to the three join predicates. This also resolves the conditional-uniqueness complexity described in the original issue.

    Tracked as witan task tk-fix-un-deduped-user-joins-and-missing-platform-k-fec3ca.

  4. quazi-h commented on Oct 6, 2026

    @quazi-h
    ContributorAuthor

    Reopening. This closed automatically when a435636 (#2400) merged. The squash commit kept a Closes .../issues/1957 line from one of the branch's commits, but the PR description says #2400 is "same fan-out defect family; that issue investigates conditional uniqueness in a sibling model and isn't fully resolved by this PR". The conditional uniqueness question this issue asks has not been investigated or answered.

  5. reopened this on Oct 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions