diff --git a/lib/grade/grade_category.php b/lib/grade/grade_category.php
index <HASH>..<HASH> 100644
--- a/lib/grade/grade_category.php
+++ b/lib/grade/grade_category.php
@@ -1098,6 +1098,10 @@ class grade_category extends grade_object {
      * @return object grade_category instance for course grade
      */
     function fetch_course_category($courseid) {
+        if (empty($courseid)) {
+            debugging('Missing course id!');
+            return false;
+        }
 
         // course category has no parent
         if ($course_category = grade_category::fetch(array('courseid'=>$courseid, 'parent'=>null))) {
add debug code for missing course id when getting course grading category; merged from MOODLE_<I>_STABLE