MDL-42301 I noticed the following error when I deleted a course from the course management interface
The reason for the error was get_courses was returning an outdated list of courses. However during the course delete process fix_course_sortorder() is called , which is supposed to purge the related caches, but that is not what is happening. For some reason the caches are not purged and hence the error is generated.
I tried using cache_helper::purge_by_event('changesincoursecat'); and the error still persists, however if I purge the catch by definition for 'coursecat' in delete_course() , everything works as expected.
This is an edge case scenario , I am able to reproduce this only in one of my Moodle installs. All other installs work as expected. I do not have any noticeable difference in settings between the installs, hence am not exactly sure how to replicate it on a fresh install.