Skip to content

feat: replace enterprise_support import with GradeEventContextRequest…#297

Open
kiram15 wants to merge 2 commits into
release-ulmofrom
kiram15/ENT-11563
Open

feat: replace enterprise_support import with GradeEventContextRequest…#297
kiram15 wants to merge 2 commits into
release-ulmofrom
kiram15/ENT-11563

Conversation

@kiram15
Copy link
Copy Markdown

@kiram15 kiram15 commented May 18, 2026

Description

Replaces get_enterprise_event_context in lms/djangoapps/grades/events.py with GradeEventContextRequested.run_filter.

The filter pipeline is expected to return the final event context object, so course_grade_passed_first_time now 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
Screenshot 2026-05-18 at 8 29 18 PM

And in the COURSE_GRADE_PASSED_FIRST_TIME event sender also has the enterprise uuid information
Screenshot 2026-05-18 at 8 31 56 PM

Also tested with a user that doesn't have any enterprise associations, just prints enterprise uuid empty
Screenshot 2026-05-18 at 8 33 45 PM

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.

  • Does this change depend on other changes elsewhere?
  • Any special concerns or limitations? For example: deprecations, migrations, security, or accessibility.
  • If your database migration can't be rolled back easily.

Copilot AI review requested due to automatic review settings May 18, 2026 20:57
@kiram15 kiram15 marked this pull request as draft May 18, 2026 20:58
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_context import and replace its call in course_grade_passed_first_time with GradeEventContextRequested.run_filter, replacing the context when a non-None value is returned.
  • Add GradeEventContextFilterTest covering both the enriched-context and None-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.

Comment thread lms/djangoapps/grades/events.py Outdated
Comment thread lms/djangoapps/grades/events.py Outdated
Comment thread lms/djangoapps/grades/tests/test_events.py Outdated
Comment thread lms/djangoapps/grades/events.py Outdated
Comment thread lms/djangoapps/grades/events.py
@pwnage101
Copy link
Copy Markdown
Member

pwnage101 commented May 18, 2026

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):

  • directly call the course_grade_passed_first_time function with fabricated arguments.
  • emit a django signal with fabricated data and let the listen_for_course_grade_passed_first_time handler call the course_grade_passed_first_time function.
  • seed/create a test course in devstack, complete it, let it emit the COURSE_GRADE_PASSED_FIRST_TIME signal which triggers the listen_for_course_grade_passed_first_time handler which calls the course_grade_passed_first_time function.

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 make lms-logs. If not, then you'll likely just have to figure out a minor tweak to settings to make the tracking logger direct to stdout.

Then, please update the PR description with screenshots and/or logger clippings.

@kiram15 kiram15 force-pushed the kiram15/ENT-11563 branch from c9316d5 to ad19290 Compare May 19, 2026 16:02
Copy link
Copy Markdown
Member

@pwnage101 pwnage101 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

code looks good, tests just need to be updated.

Comment thread lms/djangoapps/grades/tests/test_events.py Outdated
@pwnage101 pwnage101 marked this pull request as ready for review May 19, 2026 23:32
Copilot AI review requested due to automatic review settings May 19, 2026 23:32
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

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

Comment thread lms/djangoapps/grades/events.py
Comment thread lms/djangoapps/grades/events.py
Comment thread lms/djangoapps/grades/events.py Outdated
Copilot AI review requested due to automatic review settings May 20, 2026 21:15
@kiram15 kiram15 force-pushed the kiram15/ENT-11563 branch from ec846fc to d55650a Compare May 20, 2026 21:15
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

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

Comment thread lms/djangoapps/grades/tests/test_events.py
Comment thread lms/djangoapps/grades/tests/test_events.py Outdated
Comment thread lms/djangoapps/grades/tests/test_events.py Outdated
Comment thread lms/djangoapps/grades/tests/test_events.py Outdated
Comment thread lms/djangoapps/grades/events.py Outdated
@kiram15 kiram15 force-pushed the kiram15/ENT-11563 branch from d55650a to a93dba2 Compare May 20, 2026 21:59
@kiram15 kiram15 force-pushed the kiram15/ENT-11563 branch from a93dba2 to 866a1a5 Compare May 20, 2026 22:30
Copilot AI review requested due to automatic review settings May 20, 2026 23:06
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 7 out of 7 changed files in this pull request and generated 3 comments.

Comment thread lms/djangoapps/grades/tests/test_events.py Outdated
Comment thread lms/djangoapps/grades/tests/test_events.py Outdated
Comment thread lms/djangoapps/grades/tests/test_events.py Outdated
@kiram15 kiram15 force-pushed the kiram15/ENT-11563 branch from 59cca21 to 3ce616e Compare May 20, 2026 23:25
Copy link
Copy Markdown
Member

@pwnage101 pwnage101 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Just one nit.

Comment on lines +284 to +290
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,
):
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

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.

3 participants