fix: add safe enterprise context defaults to survive stale Mako cache after PR #38094#38642
Draft
Copilot wants to merge 2 commits into
Draft
fix: add safe enterprise context defaults to survive stale Mako cache after PR #38094#38642Copilot wants to merge 2 commits into
Copilot wants to merge 2 commits into
Conversation
… crashes Agent-Logs-Url: https://github.com/openedx/openedx-platform/sessions/9f1afa3c-8e4e-45be-b752-62cb9fd8bb5b Co-authored-by: kiram15 <31229189+kiram15@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Investigate stale Mako compiled cache for dashboard error
fix: add safe enterprise context defaults to survive stale Mako cache after PR #38094
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.
Description
PR #38094 removed
consent_required_coursesand other enterprise variables fromstudent_dashboard()context, relying onDashboardContextEnricher(viaDashboardRenderStartedfilter) to supply them. Deployments with a stale compiled Mako cache at/tmp/mako_lms/…/dashboard.html.pystill contain the pre-#38094 line:When
consent_required_coursesis absent from context, Mako resolves it toUndefined. Theinmembership test onUndefinedraisesTypeError: argument of type 'Undefined' is not iterable, crashing the dashboard for all users until the cache is regenerated.Changes:
student/views/dashboard.py— adds safe defaults to the context dict before the filter runs, so stale-cache code paths don't crash and non-enterprise deployments degrade gracefully:DashboardContextEnricherwill overwrite these with real values when the enterprise package is active.lms/envs/common.py— changesfail_silently: False→fail_silently: Truefor theDashboardContextEnricherpipeline entry, matching the pattern already used byAccountSettingsReadOnlyFieldsStep. Withfail_silently: Falseany exception inside the enricher propagates uncaught and crashes the entire dashboard render.Supporting information
dashboard.html.pyline 243:show_consent_link = (session_id in consent_required_courses)— this line was removed from source in feat: remove enterprise dashboard context imports (ENT-11569) #38094 but persists in stale compiled Mako artifacts.Testing instructions
show_consent_link = (session_id in consent_required_courses)inside the% forloop ofdashboard.html(or reproduce by not clearing/tmp/mako_lms/after deploying feat: remove enterprise dashboard context imports (ENT-11569) #38094).TypeError; with this fix it renders correctly (show_consent_linkevaluatesFalse).DashboardContextEnricherare active (the filter overwrites the empty defaults).Deadline
Urgent — active production 500s on the learner dashboard.
Other information
The root fix for the crash is providing
consent_required_courses = set()in context. Thefail_silentlychange is a correctness/consistency fix: the dashboard filter should not be able to kill the dashboard render on its own.Original prompt
The user believes a production dashboard error after merging PR #38094 may be caused by a stale compiled Mako cache rather than current source code. Investigate where the compiled line
show_consent_link = (session_id in consent_required_courses)originated from in openedx/openedx-platform on master, identify the source template/code that would have generated that compiled Mako line, and explain whether the issue is likely stale compiled templates versus a current source mismatch. Focus on locating the originating source in the repository history/current code and provide the minimal explanation needed for the user.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 does not always inject every variable the templates still reference, the dashboar...This pull request was created from Copilot chat.