fix: make enterprise DashboardContextEnricher fail-safe and add context defaults#38641
Draft
Copilot wants to merge 2 commits into
Draft
fix: make enterprise DashboardContextEnricher fail-safe and add context defaults#38641Copilot wants to merge 2 commits into
Copilot wants to merge 2 commits into
Conversation
…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
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.
PR #38094 removed enterprise context variables from
student_dashboard()in favor of aDashboardContextEnricherfilter pipeline, but left two unsafe conditions that can crash the learner dashboard.Description
Problem: Two issues introduced by PR #38094:
fail_silently: FalseforDashboardContextEnricher— any import failure (e.g., enterprise package not yet shippingDashboardContextEnricher) or runtime exception in the enricher propagates uncaught and 500s the entire dashboard. Inconsistent with the identicalAccountSettingsReadOnlyFieldsStepwhich correctly usesfail_silently: True.enterprise_messageandenterprise_learner_portal_enabled_messagewere removed from the view context with no fallback. While Mako treatsUndefinedas falsy (so the%ifguards don't crash), the template contract is now implicit and fragile.Changes:
lms/envs/common.py:fail_silently: False→fail_silently: TrueforDashboardContextEnricher. 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 forenterprise_messageandenterprise_learner_portal_enabled_messagein the context dict.DashboardContextEnricheroverrides these for enterprise users when available; non-enterprise and fallback paths see''(falsy), suppressing the banner blocks in the template.Affected roles: Learners (dashboard render reliability); Enterprise learners (banner display when enricher is healthy).
Supporting information
consent_required_coursesUndefined indashboard.html(already fixed by feat: remove enterprise dashboard context imports (ENT-11569) #38094 template cleanup)fail_silentlybehavior: import failures and runtime exceptions are re-raised whenFalse, silently logged whenTrueTesting instructions
OPEN_EDX_FILTERS_CONFIGset to an intentionally broken enricher path — dashboard should still render (not 500) withfail_silently: True.DashboardContextEnricher— enterprise banners should still appear (enricher overrides the''defaults).Deadline
None.
Other information
''defaults in the context dict are intentionally placed beforeDashboardRenderStarted.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_notificationget_enterprise_learner_portal_contextis_enterprise_learnerenterprise_messageconsent_required_coursesand also deleted the old helper
get_consent_required_coursesfromopenedx/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:
show_consent_link = (session_id in consent_required_courses)fromlms/templates/dashboard.html.show_consent_linkfrom the include args passed to_dashboard_course_listing.html._dashboard_course_listing.html._dashboard_show_consent.html.Those removals are consistent with deleting the old consent UI.
However, the current
masterversion oflms/templates/dashboard.htmlstill contains a top-level block:while the PR explicitly removed
enterprise_messagefrom the dashboard view context. So the template still expects enterprise data that the view no longer passes. In Mako, an omitted variable becomesUndefined, 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 aboutconsent_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.pylost bothenterprise_messageandconsent_required_coursesfrom context. citeturn0commentaryto=functions.get-github-data1turn0commentaryto=functions.get-github-data2turn0commentaryto=functions.get-github-data3The concrete mistake
The mistake was assuming the event-pipeline replacement fully covered the old template contract. The PR added a new event pipeline entry:
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.