diff --git a/lib/datalib.php b/lib/datalib.php
index <HASH>..<HASH> 100644
--- a/lib/datalib.php
+++ b/lib/datalib.php
@@ -698,6 +698,11 @@ function get_courses_wmanagers($categoryid=0, $sort="c.sortorder ASC", $fields=a
         return array(); // no courses!
     }
 
+    $CFG->coursemanager = trim($CFG->coursemanager);
+    if (empty($CFG->coursemanager)) {
+        return $courses;
+    }
+
     $managerroles = split(',', $CFG->coursemanager);
     $catctxids = '';
     if (count($managerroles)) {
datalib:get_courses_wmanagers() handle empty $CFG->coursemanager more gracefully

Having no roles set as coursemanager is a valid setting.
get_courses_wmanagers() should not produce invalid SQL on it...
actually, it should not even try to get the course managers.