# Modulestore does not get course

**URL:** <https://discuss.openedx.org/t/modulestore-does-not-get-course/10662>\
**Category:** Site Operations Help\
**Created:** [July 11, 2023, 3:04am UTC](https://discuss.openedx.org/t/modulestore-does-not-get-course/10662 "2023-07-11T03:04:39Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![jacatove](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.openedx.org/jacatove/32/3343_2.png) [@jacatove](https://discuss.openedx.org/u/jacatove)\
**Post date:** [July 11, 2023, 3:04am UTC](https://discuss.openedx.org/t/modulestore-does-not-get-course/10662/1 "2023-07-11T03:04:39Z")

</div>

Once a course is created in studio the course\_published signal is emitted, therefore some receivers trigger some async tasks which end up failing because the modulestore does not get the already created course.

The following procedure will demonstrate the issue:

1. Prepare the Org, Number and Run for the course we are going to create.
2. Get in the cms shell and execute this code.

```auto
from xmodule.modulestore.django import modulestore
from opaque_keys.edx.keys import CourseKey

modulestore().get_course(CourseKey.from_string('course-v1:ORG+NUMBER+RUN))

```

you won’t get anything since we haven’t created anything yet.

1. Create the course in studio.

2. Use the cms shell in step 2 and execute `modulestore().get_course(CourseKey.from_string('course-v1:ORG+NUMBER+RUN))` again. It returns NOTHING!. Reimporting the modulestore makes no difference.

3. Check mongo to make sure it is there.

```auto
use edxapp

db.modulestore.active_versions.find({"search_targets.wiki_slug": "ORG.NUMBER.RUN"})

```

1. Close the cms shell and repeat step 2. Now you get the course when doing `modulestore().get_course(CourseKey.from_string('course-v1:ORG+NUMBER+RUN))`

I think something similar is happening with the cms-worker when doing the tasks because its modulestore for some reason is not “updated”. Has anyone experienced this?

**Notes:**

- Tested in nutmeg and olive.
- Tested in kubernetes and single server installation.
- Some errors are of this kind:
  - `Task cms.djangoapps.contentstore.tasks.update_outline_from_modulestore_task[78fa194f-077b-4b9b-b1f1-be2143279345] raised unexpected: AttributeError("'NoneType' object has no attribute 'get_children'")`
  - `cms.djangoapps.contentstore.tasks.update_search_index[8bba4888-67f6-4bae-8336-807f31ddfe2e]: Search indexing error for complete course course-v1:AWS+EDD5+2023 - Error(s) present during indexing - ['General indexing error occurred']`
  - `ERROR/ForkPoolWorker-7] Indexing error encountered, courseware index may be out of date course-v1:ORG+NUMBER+RUN - AttributeError("'NoneType' object has no attribute 'id'")`

---

<div class="post-metadata">

**Author:** ![Agrendalath](https://avatars.discourse-cdn.com/v4/letter/a/c68b51/32.png) [@Agrendalath](https://discuss.openedx.org/u/Agrendalath)\
**Post date:** [July 11, 2023, 11:48am UTC](https://discuss.openedx.org/t/modulestore-does-not-get-course/10662/2 "2023-07-11T11:48:19Z")

</div>

@jacatove, I don’t know how `cms-shell` caches the courses, but it’s always been like this. However, these Celery tasks are likely failing due to race conditions.

If you add `time.sleep(10)` above [this line](https://github.com/openedx/edx-platform/blob/838f6ea4da746d9d52046179991ab932c688ffd1/cms/djangoapps/contentstore/outlines.py#L333), you should no longer see this error in the Celery task that generates the Course Outline (`cms.djangoapps.contentstore.tasks.update_outline_from_modulestore_task`).

I also see these errors in our Celery logs, but it happens only when a new course is created; these tasks work properly for re-running the courses. A newly created course has no content, so I believe it’s not a big deal - these tasks will run again once you add some content to the course and publish it.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex020/uploads/openedx/original/2X/e/e0015f89e879bc75925b71fd11133ab15fe98297.png) [@system](https://discuss.openedx.org/u/system)\
**Post date:** [October 9, 2023, 11:48am UTC](https://discuss.openedx.org/t/modulestore-does-not-get-course/10662/3 "2023-10-09T11:48:34Z")

</div>

Closed on October 9, 2023, 11:48am UTC

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.
