(originally taken from the Open edX Slack instance)
I am curious if someone could help me unravel a mystery around 500 errors we see occasionally from the LMS in the course_modes app’s views.py.
Our system is failing to retrieve a course run’s info from Mongo but I’m a little stumped as to why.
Link to offending piece of code: https://github.com/openedx/edx-platform/blob/05890d25b69ab618fb166964c53f4ed3d70e8a77/common/djangoapps/course_modes/views.py#L362-L378
Error observed:
builtins.AttributeError: ‘NoneType’ object has no attribute ‘has_started’
… {StackTrace} …
File “/edx/app/edxapp/edx-platform/common/djangoapps/course_modes/views.py”, line 142, in get
return self._redirect_to_course_or_dashboard(course, course_key, request.user)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “/edx/app/edxapp/edx-platform/common/djangoapps/course_modes/views.py”, line 415, in _redirect_to_course_or_dashboard
if course.has_started() or user.is_staff:
^^^^^^^^^^^^^^^^^^
AttributeError: ‘NoneType’ object has no attribute ‘has_started’
So it seems like a null course has been passed to the _redirect_to_course_or_dashboard function… but I’m trying to understand why it’s null. We attempt to retrieve the course run here: edx-platform/common/djangoapps/course_modes/views.py at 05890d25b69ab618fb166964c53f4ed3d70e8a77 · openedx/edx-platform · GitHub
Querying Mongo directly, I’m able to retrieve information about this course run… (some data scrubbed for sharing purposes)
db.modulestore.active_versions.find({"course": "some-course", "org": "some-org", "run": "1T2022"}).pretty()
{
“_id” : ObjectId(“621727931f9260e1e9a873ba”),
“org” : “some-org”,
“course” : “some-course”,
“run” : “1T2022”,
“edited_by” : 10442141,
“edited_on” : ISODate(“2022-02-24T06:37:07.373Z”),
“last_update” : ISODate(“2022-03-11T05:08:57.515Z”),
“versions” : {
“draft-branch” : ObjectId(“622ad9695eaf4ae29c569336”),
“published-branch” : ObjectId(“622ad9695eaf4ae29c569337”)
},
“schema_version” : 1,
“search_targets” : {
“wiki_slug” : “some-course”
}
}
I was also able to successfully retrieve course info via Mongo using the draft-branch and published-branch ObjectIDs.
Digging a bit further, I see another error in our logs related to my 500 error:
Traceback (most recent call last):
File “/edx/app/edxapp/venvs/edxapp/lib/python3.11/site-packages/edx_django_utils/monitoring/internal/utils.py”, line 112, in function_trace
yield
File “/usr/lib/python3.11/contextlib.py”, line 81, in inner
return func(*args, **kwds)
^^^^^^^^^^^^^^^^^^^
File “/edx/app/edxapp/edx-platform/xmodule/modulestore/split_mongo/split_draft.py”, line 61, in get_course
return super().get_course(course_id, depth=depth, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “/edx/app/edxapp/edx-platform/xmodule/modulestore/split_mongo/split.py”, line 1106, in get_course
return self._get_structure(course_id, depth, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “/edx/app/edxapp/edx-platform/xmodule/modulestore/split_mongo/split.py”, line 1094, in _get_structure
structure_entry = self._lookup_course(structure_id, head_validation=head_validation)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “/edx/app/edxapp/edx-platform/xmodule/modulestore/split_mongo/split.py”, line 860, in _lookup_course
raise ItemNotFoundError(f’Structure: {version_guid}')
xmodule.modulestore.exceptions.ItemNotFoundError: Structure: 623043c73b501fd206fdc2d6
Are we trying to retrieve the course run’s info with an ObjectId of 623043c73b501fd206fdc2d6? Shouldn’t this match one of the versions of the course stored in Mongo (assuming the published-branch version?)
Thanks to advice from @dave, I then looked at the split_modulestore_django_splitmodulestorecourseindex table and discovered that the draft_version and published_version pointers for the course run seem to be out of sync:
SELECT course_id, objectid, draft_version, published_version FROM split_modulestore_django_splitmodulestorecourseindex where course_id = 'course-v1:some-org+some-course+1T2022';
Which resulted in the following values being returned:
objectid: 621727931f9260e1e9a873ba
draft_version: 623043c2949df6cd1bc8febe
published_version: 623043c73b501fd206fdc2d6.
Has this happened to anyone else? Any words of advice? Could I manually update the pointers in the split_modulestore_django_splitmodulestorecourseindex table to the current values in Mongo and “fix” the course? Any gotchas here?
Thanks!