diff --git a/course/classes/category.php b/course/classes/category.php index 5812abdf133..15eb32a60d8 100644 --- a/course/classes/category.php +++ b/course/classes/category.php @@ -1582,7 +1582,10 @@ class core_course_category implements renderable, cacheable_object, IteratorAggr } // Prepare the list of core_course_list_element objects. foreach ($ids as $id) { - $courses[$id] = new core_course_list_element($records[$id]); + // If a course is deleted after we got the cache entry it may not exist in the database anymore. + if (!empty($records[$id])) { + $courses[$id] = new core_course_list_element($records[$id]); + } } } return $courses; @@ -1792,7 +1795,10 @@ class core_course_category implements renderable, cacheable_object, IteratorAggr } // Prepare the list of core_course_list_element objects. foreach ($ids as $id) { - $courses[$id] = new core_course_list_element($records[$id]); + // If a course is deleted after we got the cache entry it may not exist in the database anymore. + if (!empty($records[$id])) { + $courses[$id] = new core_course_list_element($records[$id]); + } } } return $courses;