From 77fe61c19c156465ecc084b90f2a6f732e821444 Mon Sep 17 00:00:00 2001 From: Deborah Kaplan Date: Fri, 14 Mar 2025 08:45:32 -0400 Subject: [PATCH] fix: CourseEnrollment list serializer error on deleted Course (#36378) If a course is deleted or unpublished, the CourseEnrollment list serializer was causing a AttributeErrors when called for a learner who had been enrolled in the formerly-existing course. Why no test? Because cache invalidation is the worst problem. tl;dr I could create a mock response for the `course_overview` property, but if I mocked up a response to the queryset filter in `CourseEnrollmentsApiListView`, I was effectively guessing that my code worked correctly and then creating a mock response that was an assertion of correctness. That would make any mocked test deceptive; it would appear to test behavior but it would actually just test that I had constructed a mock that passed the test. I wanted to make an actual test for what would happen if a Course was deleted, so I made one character code fix, and then spent two days unsuccessfully attempting to completely clear out the ModuleStore so I could actually test what would happen in this instance. IMO an actual verification by hand (which I performed, and it works) was the better part of valor. in short, cache invalidation aaaaaaaaargh. FIXES: APER-3913 --- openedx/core/djangoapps/enrollments/views.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/openedx/core/djangoapps/enrollments/views.py b/openedx/core/djangoapps/enrollments/views.py index 620575a506..8f4c1f7de0 100644 --- a/openedx/core/djangoapps/enrollments/views.py +++ b/openedx/core/djangoapps/enrollments/views.py @@ -1017,7 +1017,7 @@ class CourseEnrollmentsApiListView(DeveloperErrorViewMixin, ListAPIView): emails = form.cleaned_data.get("email") if course_id: - queryset = queryset.filter(course_id=course_id) + queryset = queryset.filter(course__id=course_id) if usernames: queryset = queryset.filter(user__username__in=usernames) if emails: