openedx / openedx/openedx-platform
Debug toolbar causes crashes viewing course in devstack
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 8.2k
- Forks
- 4.4k
- Avg merge
- 6d 18h
- Merged PRs (30d)
- 42
Description
On some pages, the lms or cms crashes with a traceback involving the debug_toolbar and a type error:
Traceback (most recent call last):
File "/openedx/venv/lib/python3.11/site-packages/django/core/handlers/exception.py", line 55, in inner
response = get_response(request)
^^^^^^^^^^^^^^^^^^^^^
File "/openedx/venv/lib/python3.11/site-packages/debug_toolbar/middleware.py", line 145, in __call__
return self._postprocess(request, response, toolbar)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/openedx/venv/lib/python3.11/site-packages/debug_toolbar/middleware.py", line 182, in _postprocess
panel.generate_stats(request, response)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/openedx/venv/lib/python3.11/site-packages/debug_toolbar/panels/cache.py", line 212, in generate_stats
self.record_stats(
^
File "/openedx/venv/lib/python3.11/site-packages/debug_toolbar/panels/__init__.py", line 194, in record_stats
self.toolbar.store.save_panel(
^
File "/openedx/venv/lib/python3.11/site-packages/debug_toolbar/store.py", line 122, in save_panel
cls._request_store[request_id][panel_id] = serialize(data)
^^^^^^^^^^^^^^^
File "/openedx/venv/lib/python3.11/site-packages/debug_toolbar/store.py", line 32, in serialize
return json.dumps(data, cls=DebugToolbarJSONEncoder)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/opt/pyenv/versions/3.11.8/lib/python3.11/json/__init__.py", line 238, in dumps
**kw).encode(obj)
^^^^^^^^^^^
File "/opt/pyenv/versions/3.11.8/lib/python3.11/json/encoder.py", line 200, in encode
chunks = self.iterencode(o, _one_shot=True)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/opt/pyenv/versions/3.11.8/lib/python3.11/json/encoder.py", line 258, in iterencode
return _iterencode(o, 0)
^^^^^^^^^^^^^^^^^
Exception Type: TypeError at /courses/course-v1:OpenedX+DemoX+DemoCourse/about
Exception Value: keys must be str, int, float, bool or None, not tuple
To reproduce:
- Deploy a Tutor dev master devstack, with current master branch of edx-platform bind-mounted:
# with tutor at git master
tutor config save
tutor mounts add ./edx-platform
tutor images build openedx-dev
tutor dev launch
- Create a user and import the demo course:
tutor dev do createuser --staff --superuser samuel samuel@example.com --password password
tutor dev do importdemocourse
- Log in as that user. You should be redirected to http://apps.local.openedx.io:1996/learner-dashboard/
- Click "Explore courses". This should take you to http://local.openedx.io:8000/courses
- Find the "Open edX Demo Course" and click "Learn More"
- Observe the debug crash page.
The page doesn't always crash. It most commonly crashes in the first few loads, then after that it consistently succeeds.
I also observe this on other requests relating to the demo course.
For example, clicking the "View this course as: " can fail,
and in the network requests you will see a 500 error from the request to http://local.openedx.io:8000/courses/course-v1:OpenedX+DemoX+DemoCourse/masquerade .
The logs will show a similar traceback:
the traceback
lms-1 | 2025-08-01 01:13:35,253 ERROR 54 [django.request] [user 4] [ip 172.18.0.1] log.py:246 - Internal Server Error: /courses/course-v1:OpenedX+DemoX+DemoCourse/masquerade
lms-1 | Traceback (most recent call last):
lms-1 | File "/openedx/venv/lib/python3.11/site-packages/django/core/handlers/exception.py", line 55, in inner
lms-1 | response = get_response(request)
lms-1 | ^^^^^^^^^^^^^^^^^^^^^
lms-1 | File "/openedx/venv/lib/python3.11/site-packages/debug_toolbar/middleware.py", line 145, in __call__
lms-1 | return self._postprocess(request, response, toolbar)
lms-1 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
lms-1 | File "/openedx/venv/lib/python3.11/site-packages/debug_toolbar/middleware.py", line 182, in _postprocess
lms-1 | panel.generate_stats(request, response)
lms-1 | File "/openedx/venv/lib/python3.11/site-packages/debug_toolbar/panels/request.py", line 63, in generate_stats
lms-1 | self.record_stats({"session": sanitize_and_sort_request_vars(session_data)})
lms-1 | File "/openedx/venv/lib/python3.11/site-packages/debug_toolbar/panels/__init__.py", line 194, in record_stats
lms-1 | self.toolbar.store.save_panel(
lms-1 | File "/openedx/venv/lib/python3.11/site-packages/debug_toolbar/store.py", line 122, in save_panel
lms-1 | cls._request_store[request_id][panel_id] = serialize(data)
lms-1 | ^^^^^^^^^^^^^^^
lms-1 | File "/openedx/venv/lib/python3.11/site-packages/debug_toolbar/store.py", line 32, in serialize
lms-1 | return json.dumps(data, cls=DebugToolbarJSONEncoder)
lms-1 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
lms-1 | File "/opt/pyenv/versions/3.11.8/lib/python3.11/json/__init__.py", line 238, in dumps
lms-1 | **kw).encode(obj)
lms-1 | ^^^^^^^^^^^
lms-1 | File "/opt/pyenv/versions/3.11.8/lib/python3.11/json/encoder.py", line 200, in encode
lms-1 | chunks = self.iterencode(o, _one_shot=True)
lms-1 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
lms-1 | File "/opt/pyenv/versions/3.11.8/lib/python3.11/json/encoder.py", line 258, in iterencode
lms-1 | return _iterencode(o, 0)
lms-1 | ^^^^^^^^^^^^^^^^^
lms-1 | TypeError: keys must be str, int, float, bool or None, not CourseLocator
Removing the DEBUG TOOLBAR section from cms/envs/devstack.py and lms/envs/devstack.py appears to fix the problem,
but I'm unsure if it's a problem in the debug toolbar,
or if there is data in an incorrect type.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with cms/envs/devstack.py and lms/envs/devstack.py, then inspect the debug_toolbar traceback and the failing course-page requests using the provided Tutor devstack reproduction steps. Determine whether the toolbar or the request data produces unsupported dictionary keys; done means the debug toolbar remains enabled and course, masquerade, and related requests no longer return 500 errors.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- django, python
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 50/100