feat: replace enterprise_support import with GradeEventContextRequest…#297
feat: replace enterprise_support import with GradeEventContextRequest…#297kiram15 wants to merge 2 commits into
Conversation
There was a problem hiding this comment.
Pull request overview
Replaces the direct import of get_enterprise_event_context in lms/djangoapps/grades/events.py with a call to the GradeEventContextRequested openedx-filter, decoupling the grades app from openedx.features.enterprise_support. The enterprise context enrichment is now provided via a pluggable filter pipeline (implemented in edx-enterprise), letting the platform fail open if no pipeline step is configured.
Changes:
- Drop the
get_enterprise_event_contextimport and replace its call incourse_grade_passed_first_timewithGradeEventContextRequested.run_filter, replacing the context when a non-Nonevalue is returned. - Add
GradeEventContextFilterTestcovering both the enriched-context andNone-return paths.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| lms/djangoapps/grades/events.py | Swap enterprise import for GradeEventContextRequested.run_filter to source the grade event context. |
| lms/djangoapps/grades/tests/test_events.py | Add unit tests asserting the filter is invoked and that a None return preserves the original context. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
Please test this code path in devstack, not just running unit tests. I'll leave it up to you to determine the best way to do so, but off the top of my head, here are some options (from least to most end-to-end):
Ultimately, devstack inherits from the default EVENT_TRACKING_BACKENDS setting which logs tracking events to the "tracking" logger. If you're lucky, that simply ends up in the output of Then, please update the PR description with screenshots and/or logger clippings. |
c9316d5 to
ad19290
Compare
pwnage101
left a comment
There was a problem hiding this comment.
code looks good, tests just need to be updated.
ec846fc to
d55650a
Compare
d55650a to
a93dba2
Compare
a93dba2 to
866a1a5
Compare
59cca21 to
3ce616e
Compare
| with ( | ||
| patch( | ||
| 'lms.djangoapps.grades.events.contexts.course_context_from_course_id', | ||
| return_value=original_context, | ||
| ), | ||
| patch('lms.djangoapps.grades.events.tracker') as mock_tracker, | ||
| ): |
There was a problem hiding this comment.
Nit: IMO it makes the code harder to understand when you have some patch() commands inside a context manager, and some as a decorator on the test method. You want to be able to read a pile of patches in one place and not be surprised when something else is patched in a different place. Please migrate all patches to be in one place, ideally as all decorators.
Description
Replaces
get_enterprise_event_contextin lms/djangoapps/grades/events.py withGradeEventContextRequested.run_filter.The filter pipeline is expected to return the final event context object, so
course_grade_passed_first_timenow uses the returned context directly rather than merging enterprise-specific fields into a base context.If the filter raises an exception, the error is logged and re-raised.
You can see it enriching the payload with the enterprise uuid correctly when fired directly

And in the COURSE_GRADE_PASSED_FIRST_TIME event sender also has the enterprise uuid information

Also tested with a user that doesn't have any enterprise associations, just prints enterprise uuid empty

Supporting information
Jira - ENT-11563
Testing instructions
https://2u-internal.atlassian.net/wiki/spaces/SOL/pages/3710353504/Enterprise+Plugin+Ticket+Runbook
openedx-filters change is already merged into master, but make sure you have the most recent version pulled.
edx-enterprise must be checked out on pwnage101/ENT-11563 (PR)
Then run
docker compose exec test-shell bash -c "pytest -c pytest.local.ini tests/filters/ -v"to validate the tests run with the edx-enterprise changes.Deadline
"None" if there's no rush, or provide a specific date or event (and reason) if there is one.
Other information
Include anything else that will help reviewers and consumers understand the change.