Sometimes Internal Server error while calling "api/courseware/sequence" api

we have installed openedx with tutor and we are making one edu-tech platform where it is using openedx apis and maintaining its own database at the same time on another django-project in docker.

our edu-tech django-project docker is communicating with openedx apis, and sometimes openedx returns 500 Internal Error while i calling /api/courseware/sequence/{{block_key}} api.
then i traced the exception from tutor local lms logs,
this is exception made by openedx-lms.

NOTE: It happens only sometimes

lms_1                        | 2023-01-02 18:32:42,511 ERROR 19 [django.request] [user 42] [ip 172.18.0.14] log.py:224 - Internal Server Error: /api/courseware/sequence/block-v1:SOS+CSE-10+2022_r1+type@sequential+block@b9aad4acdd1f48259c3dfd92fdc216c2
lms_1                        | Traceback (most recent call last):
lms_1                        |   File "/openedx/venv/lib/python3.8/site-packages/django/core/handlers/exception.py", line 47, in inner
lms_1                        |     response = get_response(request)
lms_1                        |   File "/openedx/venv/lib/python3.8/site-packages/django/core/handlers/base.py", line 181, in _get_response
lms_1                        |     response = wrapped_callback(request, *callback_args, **callback_kwargs)
lms_1                        |   File "/opt/pyenv/versions/3.8.12/lib/python3.8/contextlib.py", line 75, in inner
lms_1                        |     return func(*args, **kwds)
lms_1                        |   File "/openedx/venv/lib/python3.8/site-packages/django/views/decorators/csrf.py", line 54, in wrapped_view
lms_1                        |     return view_func(*args, **kwargs)
lms_1                        |   File "/openedx/venv/lib/python3.8/site-packages/django/views/generic/base.py", line 70, in view
lms_1                        |     return self.dispatch(request, *args, **kwargs)
lms_1                        |   File "/openedx/venv/lib/python3.8/site-packages/rest_framework/views.py", line 509, in dispatch
lms_1                        |     response = self.handle_exception(exc)
lms_1                        |   File "/openedx/venv/lib/python3.8/site-packages/rest_framework/views.py", line 506, in dispatch
lms_1                        |     response = handler(request, *args, **kwargs)
lms_1                        |   File "/openedx/edx-platform/./openedx/core/djangoapps/courseware_api/views.py", line 596, in get
lms_1                        |     sequence, _ = get_module_by_usage_id(
lms_1                        |   File "/openedx/edx-platform/./lms/djangoapps/courseware/module_render.py", line 1070, in get_module_by_usage_id
lms_1                        |     instance = get_module_for_descriptor(
lms_1                        |   File "/openedx/edx-platform/./lms/djangoapps/courseware/module_render.py", line 387, in get_module_for_descriptor
lms_1                        |     return get_module_for_descriptor_internal(
lms_1                        |   File "/openedx/edx-platform/./lms/djangoapps/courseware/module_render.py", line 806, in get_module_for_descriptor_internal
lms_1                        |     (system, student_data) = get_module_system_for_user(
lms_1                        |   File "/openedx/edx-platform/./lms/djangoapps/courseware/module_render.py", line 724, in get_module_system_for_user
lms_1                        |     field_data = DateLookupFieldData(descriptor._field_data, course_id, user)  # pylint: disable=protected-access
lms_1                        |   File "/openedx/venv/lib/python3.8/site-packages/edx_when/field_data.py", line 51, in __init__
lms_1                        |     self._load_dates(course_id, user, use_cached=use_cached)
lms_1                        |   File "/openedx/venv/lib/python3.8/site-packages/edx_when/field_data.py", line 59, in _load_dates
lms_1                        |     for (location, field), date in api.get_dates_for_course(course_id, user, use_cached=use_cached).items():
lms_1                        |   File "/openedx/venv/lib/python3.8/site-packages/edx_when/api.py", line 186, in get_dates_for_course
lms_1                        |     allow_relative_dates = _are_relative_dates_enabled(course_id)
lms_1                        |   File "/openedx/venv/lib/python3.8/site-packages/edx_when/api.py", line 70, in _are_relative_dates_enabled
lms_1                        |     return RELATIVE_DATES_FLAG.is_enabled(course_key)
lms_1                        |   File "/openedx/edx-platform/./openedx/core/djangoapps/waffle_utils/__init__.py", line 122, in is_enabled
lms_1                        |     is_enabled_for_course = self._get_course_override_value(course_key)
lms_1                        |   File "/openedx/edx-platform/./openedx/core/djangoapps/waffle_utils/__init__.py", line 78, in _get_course_override_value
lms_1                        |     course_override = WaffleFlagCourseOverrideModel.override_value(
lms_1                        |   File "/openedx/edx-platform/./openedx/core/lib/cache_utils.py", line 74, in decorator
lms_1                        |     result = wrapped(*args, **kwargs)
lms_1                        |   File "/openedx/edx-platform/./openedx/core/djangoapps/waffle_utils/models.py", line 60, in override_value
lms_1                        |     effective = cls.objects.filter(waffle_flag=waffle_flag, course_id=course_id).order_by('-change_date').first()
lms_1                        |   File "/openedx/venv/lib/python3.8/site-packages/django/db/models/query.py", line 674, in first
lms_1                        |     for obj in (self if self.ordered else self.order_by('pk'))[:1]:
lms_1                        |   File "/openedx/venv/lib/python3.8/site-packages/django/db/models/query.py", line 280, in __iter__
lms_1                        |     self._fetch_all()
lms_1                        |   File "/openedx/venv/lib/python3.8/site-packages/django/db/models/query.py", line 1324, in _fetch_all
lms_1                        |     self._result_cache = list(self._iterable_class(self))
lms_1                        |   File "/openedx/venv/lib/python3.8/site-packages/django/db/models/query.py", line 51, in __iter__
lms_1                        |     results = compiler.execute_sql(chunked_fetch=self.chunked_fetch, chunk_size=self.chunk_size)
lms_1                        |   File "/openedx/venv/lib/python3.8/site-packages/django/db/models/sql/compiler.py", line 1175, in execute_sql
lms_1                        |     cursor.execute(sql, params)
lms_1                        |   File "/openedx/venv/lib/python3.8/site-packages/django/db/backends/utils.py", line 66, in execute
lms_1                        |     return self._execute_with_wrappers(sql, params, many=False, executor=self._execute)
lms_1                        |   File "/openedx/venv/lib/python3.8/site-packages/django/db/backends/utils.py", line 75, in _execute_with_wrappers
lms_1                        |     return executor(sql, params, many, context)
lms_1                        |   File "/openedx/venv/lib/python3.8/site-packages/django/db/backends/utils.py", line 78, in _execute
lms_1                        |     self.db.validate_no_broken_transaction()
lms_1                        |   File "/openedx/venv/lib/python3.8/site-packages/django/db/backends/base/base.py", line 447, in validate_no_broken_transaction
lms_1                        |     raise TransactionManagementError(
lms_1                        | django.db.transaction.TransactionManagementError: An error occurred in the current transaction. You can't execute queries until the end of the 'atomic' block.
lms_1                        | [pid: 19|app: 0|req: 28631/59539] 172.18.0.6 () {40 vars in 950 bytes} [Mon Jan  2 18:32:42 2023] GET /api/courseware/sequence/block-v1:SOS+CSE-10+2022_r1+type@sequential+block@b9aad4acdd1f48259c3dfd92fdc216c2 => generated 9585 bytes in 317 msecs (HTTP/1.1 500) 7 headers in 507 bytes (1 switches on core 0)

So what i did is following:

  • i installed openedx with tutor ubuntu server.
  • i made one seperate django-projcet and hosted in docker on same server.
  • that seperate django-project is calling apis of openedx one of the api its calling is this /api/courseware/sequence/{{block}}.
  • its calling this api very frequently.
  • a lot of times it returns 200 response but sometimes it returns 500 internal error(from openedx side above shown is exception of that).

Hi Amit, we are seeing this intermittently on an olive.4 install — did you ever find the issue?