fix: record open-course enrollments and correct dashboard metrics - #74
Open
ccantillo wants to merge 1 commit into
Open
fix: record open-course enrollments and correct dashboard metrics#74ccantillo wants to merge 1 commit into
ccantillo wants to merge 1 commit into
Conversation
ccantillo
marked this pull request as ready for review
September 1, 2026 22:23
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fix dashboard metrics not updating — backend
Refs nau-technical#1021
Related MFE PRs:
frontend-app-corporate,frontend-app-partner-catalogs(cache-invalidation fixes; they work without this PR but the metrics they
refresh are only correct with it).
Summary
The corporate dashboards (general partner dashboard, catalog dashboard, and
course cards) never reflected enrollments, certified learners, or completion
activity. End-to-end testing against the real DRF viewsets showed the root
causes are in this repo, not in the MFEs:
CatalogCourseEnrollmentrecord, and that record is what every metriccounts — so dashboards and course cards stayed at 0.
certified_countSQL annotation always returned 0 due to two bugs.count, so the general dashboard showed how many learners exist instead of
course enrollments.
manage endpoint with a 500 while computing completion rates.
What changed
partner_catalog/services/enrollments.pycreate_or_activate_course_enrollmentreturned early for open courses aftersyncing the LMS enrollment, without persisting the
CatalogCourseEnrollment.The create-or-activate block (previously only reachable by the paid path) is
extracted into
_persist_enrollment_record()and now runs for open coursestoo. Open enrollments still do not consume the paid enrollment bag:
can_consume_course_limitonly counts enrollments in paid courses.partner_catalog/services/certificates.pyTwo bugs in
annotate_certified_count:users_qs/courses_qswere built withOuterRef("pk")but used at twodifferent nesting depths — inside
Exists()(1 level, correct) and insidethe count
Subquery(2 levels). At depth 2, Django resolved the ref againstthe
GeneratedCertificatequeryset, silently matching nothing..values()with no arguments grouped by every model field (per certificaterow), so the count subquery could only ever return 1.
The four annotators now pass factory callables so the helper builds each
subquery at the correct depth (
OuterRef("pk")forExists,OuterRef(OuterRef("pk"))for the count subquery), and the count groups by aconstant to return a single distinct-user count.
partner_catalog/api/v1/views.py/serializers.pyPartnerSerializer.enrollmentspointed atlearners_count. Added a realenrollments_countannotation toPartnerViewset(active enrollments acrossthe partner's catalogs) and pointed the serializer at it.
partner_catalog/services/progress.py+edxapp_wrapper/courseware_module*compute_progress_percent_by_userraised an unhandledxmodule.modulestore.exceptions.ItemNotFoundErrorwhen a course run existedonly as a
CourseOverviewstub, turning the whole manage-catalogs requestinto a 500. The exception class is now exposed through the existing
edxapp_wrapperpattern (item_not_found_error()) and caught narrowly,returning 0.0 progress for that run.
tests/test_catalog_course_enrollment_service.pytest_new_enrollment_open_course_does_not_consume_bag_and_no_createassertedthe buggy behavior. Renamed to
..._and_creates_record; it now asserts therecord is created with
active=Truewhile the paid bag is still neverconsulted.