How-to: Delete a course (Ulmo)

This was mentioned in others discussion, but was incomplete, here is the fix with Meleisearch fix included.

# Put your course id
tutor local exec cms ./manage.py cms --setting=tutor.production delete_course 'course-v1:2600+111+222'

You should have:

from err meilisearch.errors.MeilisearchApiError: MeilisearchApiError. Error code: invalid_search_filter. Error message: Attribute course is not filterable.

To delete the index, you need the associated _pk key.

tutor local exec meilisearch sh -lc '
curl -sS \
  -H "Authorization: Bearer $MEILI_MASTER_KEY" \
  -H "Content-Type: application/json" \
  http://localhost:7700/indexes/tutor_course_info/search \
  --data-binary '"'"'{"q":"course-v1:2600+101+2024","limit":50,"attributesToRetrieve":["_pk","course","org","language","start","catalog_visibility", "content.display_name"]}'"'"'
' | sed -n '/^{/,$p' | jq

Note: sed remove the extra text printed before the json and jq format it.

You will have something like:

    {
      "_pk": "266ac44be25c40ddadde5c106c39d0f3ee40d91a",
      "course": "course-v1:2600+101+2012",
      "content": {
        "display_name": "Test cours"
      },
      "start": 1893456000.0,
      "org": "2600",
      "language": "en",
      "catalog_visibility": "both"
    }

and delete it:

tutor local exec meilisearch sh -lc '
curl -sS -X DELETE \
  -H "Authorization: Bearer $MEILI_MASTER_KEY" \
  http://localhost:7700/indexes/tutor_course_info/documents/266ac44be25c40ddadde5c106c39d0f3ee40d91a
'

Since it is an async enqueud task, if nothing changes in https://your-openedx.example/courses you may check the task status with:

# you should have task id from previous response.
tutor local exec meilisearch sh -lc '
curl -sS -H "Authorization: Bearer $MEILI_MASTER_KEY" \
  http://localhost:7700/tasks/288
'

Deletion was instant for me.

A more sustainable approach might be to add course to filterable-attributes

2 Likes