Skip to content

fix: make enterprise DashboardContextEnricher fail-safe and add context defaults#38641

Draft
Copilot wants to merge 2 commits into
masterfrom
copilot/analyze-merged-pr-38094
Draft

fix: make enterprise DashboardContextEnricher fail-safe and add context defaults#38641
Copilot wants to merge 2 commits into
masterfrom
copilot/analyze-merged-pr-38094

Conversation

Copy link
Copy Markdown

Copilot AI commented May 14, 2026

PR #38094 removed enterprise context variables from student_dashboard() in favor of a DashboardContextEnricher filter pipeline, but left two unsafe conditions that can crash the learner dashboard.

Description

Problem: Two issues introduced by PR #38094:

  1. fail_silently: False for DashboardContextEnricher — any import failure (e.g., enterprise package not yet shipping DashboardContextEnricher) or runtime exception in the enricher propagates uncaught and 500s the entire dashboard. Inconsistent with the identical AccountSettingsReadOnlyFieldsStep which correctly uses fail_silently: True.

  2. enterprise_message and enterprise_learner_portal_enabled_message were removed from the view context with no fallback. While Mako treats Undefined as falsy (so the %if guards don't crash), the template contract is now implicit and fragile.

Changes:

  • lms/envs/common.py: fail_silently: Falsefail_silently: True for DashboardContextEnricher. Matches the established pattern for enterprise filter steps; enricher failures are logged, not surfaced as 500s.

  • common/djangoapps/student/views/dashboard.py: Add explicit empty-string defaults for enterprise_message and enterprise_learner_portal_enabled_message in the context dict. DashboardContextEnricher overrides these for enterprise users when available; non-enterprise and fallback paths see '' (falsy), suppressing the banner blocks in the template.

Note: The specific Datadog crash (argument of type 'Undefined' is not iterable on show_consent_link = (session_id in consent_required_courses)) was already eliminated by PR #38094 removing that template line. These changes address the remaining crash surface and template contract gap.

Affected roles: Learners (dashboard render reliability); Enterprise learners (banner display when enricher is healthy).

Supporting information

Testing instructions

  1. Load the learner dashboard as a non-enterprise user — should render normally with no enterprise banners.
  2. Load the learner dashboard with OPEN_EDX_FILTERS_CONFIG set to an intentionally broken enricher path — dashboard should still render (not 500) with fail_silently: True.
  3. Load the learner dashboard in a full enterprise deployment with a working DashboardContextEnricher — enterprise banners should still appear (enricher overrides the '' defaults).

Deadline

None.

Other information

  • No migrations, no API changes, no deprecations.
  • The '' defaults in the context dict are intentionally placed before DashboardRenderStarted.run_filter() is called, so the enricher can freely override them.
Original prompt

The user is investigating PR #38094 in openedx/openedx-platform and wants to understand what was incorrect about the merged change and what is needed to fix it after observing production issues. Analyze the merged PR and current repository state, determine whether the dashboard templates still reference enterprise-related context variables that were removed from student_dashboard(), reconcile this with the user's note that the specific line show_consent_link = (session_id in consent_required_courses) has been removed in current deployments, and identify the actual root cause and required fix. Provide a concise explanation grounded in the code changes and any remaining template/view mismatches.

The following is the prior conversation context from the user's chat exploration (may be truncated):

User: I merged in this PR but am now seeing issues in DataDog as follows. What was incorrect about this PR, and what is needed to fix it?

Here is the information given to me from the DataDog AI
Root Cause in the Stack Trace
The crash happens in the Mako template dashboard.html.py at line 243:

show_consent_link = (session_id in consent_required_courses)

The variable consent_required_courses is Mako Undefined (not passed into the template context), so Python can't perform an in membership test on it — hence argument of type 'Undefined' is not iterable.

The call chain (confirming your coworker's description):

openedx/core/djangoapps/util/maintenance_banner.py line 42 (decorator _decorated)
→ common/djangoapps/student/views/dashboard.py line 889 (student_dashboard → render_to_response)
→ Mako template lms/templates/dashboard.html renders and hits the Undefined variable

What to Fix
The consent_required_courses context variable needs to be defined before it reaches the template. In student_dashboard() in dashboard.py, ensure consent_required_courses is included in the template context dict (likely it was removed or renamed in your recent deploy). A quick defensive fix in the template would be:

show_consent_link = (session_id in consent_required_courses) if consent_required_courses is not UNDEFINED else False

But the proper fix is to ensure the view passes consent_required_courses in the context.

Assistant: The PR was incomplete: it removed the view-side context population for enterprise dashboard data, but it did not fully remove all template references to that data. The production error is the result of that mismatch.

What was incorrect in the PR

In common/djangoapps/student/views/dashboard.py, the PR removed these imports and context values:

  • get_dashboard_consent_notification
  • get_enterprise_learner_portal_context
  • is_enterprise_learner
  • enterprise_message
  • consent_required_courses

and also deleted the old helper get_consent_required_courses from openedx/features/enterprise_support/api.py. That means the dashboard view no longer provides enterprise consent/dashboard context at all.

At the same time, the PR only partially updated the dashboard templates:

  • It did remove show_consent_link = (session_id in consent_required_courses) from lms/templates/dashboard.html.
  • It did remove show_consent_link from the include args passed to _dashboard_course_listing.html.
  • It did remove the consent include block from _dashboard_course_listing.html.
  • It deleted _dashboard_show_consent.html.

Those removals are consistent with deleting the old consent UI.

However, the current master version of lms/templates/dashboard.html still contains a top-level block:

% if enterprise_message:
    <div class="dashboard-banner">
        ${ enterprise_message | n, decode.utf8 }
    </div>
% endif

while the PR explicitly removed enterprise_message from the dashboard view context. So the template still expects enterprise data that the view no longer passes. In Mako, an omitted variable becomes Undefined, and using it in control flow can crash rendering rather than simply evaluate false. That is the underlying class of bug introduced by this PR. The same mismatch can explain the Datadog error you were given about consent_required_courses: a template path still referenced a variable after the view stopped providing it. PR data: merged May 12, 2026; 7 files changed; dashboard.py lost both enterprise_message and consent_required_courses from context. citeturn0commentaryto=functions.get-github-data1turn0commentaryto=functions.get-github-data2turn0commentaryto=functions.get-github-data3

The concrete mistake

The mistake was assuming the event-pipeline replacement fully covered the old template contract. The PR added a new event pipeline entry:

"org.openedx.learning.dashboard.render.started.v1": {
    "fail_silently": False,
    "pipeline": ["enterprise.filters.dashboard.DashboardContextEnricher"],
},

but it also removed the legacy context variables directly from student_dashboard(). If that new enrichment path ...

This pull request was created from Copilot chat.

…xt defaults

After PR #38094 removed enterprise context variables from student_dashboard()
in favor of a DashboardContextEnricher filter pipeline, two issues remained:

1. fail_silently: False could crash the entire dashboard if the enricher is
   unavailable or fails
2. enterprise_message and enterprise_learner_portal_enabled_message had no
   explicit defaults in the context dict

Changes:
- lms/envs/common.py: Changed fail_silently: False to fail_silently: True
  for DashboardContextEnricher to prevent dashboard crashes
- dashboard.py: Added explicit empty-string defaults for enterprise context
  variables so the template contract is always satisfied

Agent-Logs-Url: https://github.com/openedx/openedx-platform/sessions/9dfd421a-df10-4df0-a99f-70d73ea5378e

Co-authored-by: kiram15 <31229189+kiram15@users.noreply.github.com>
Copilot AI changed the title [WIP] Analyze production issues from merged PR #38094 fix: make enterprise DashboardContextEnricher fail-safe and add context defaults May 14, 2026
Copilot AI requested a review from kiram15 May 14, 2026 02:46
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.

2 participants