Details

    • Database:
      MySQL
    • Testing Instructions:
      Hide

      Restore the attached backup into a new course. Go to the grade book and check that it loads without error. (MDL-37676 actually fixed the restore process but it doesnt hurt to double check)

      In another course with one or more graded activities and one or more students.

      You're going to make a series of modifications before reloading the user report and the grader report so keep them open in separate tabs.

      Modify category aggregation type.

      While category aggregation is set to sum of grades set "drop lowest" to some number.

      Set some grade items to be extra credit.

      Check you dont get any errors.

      Show
      Restore the attached backup into a new course. Go to the grade book and check that it loads without error. ( MDL-37676 actually fixed the restore process but it doesnt hurt to double check) In another course with one or more graded activities and one or more students. You're going to make a series of modifications before reloading the user report and the grader report so keep them open in separate tabs. Modify category aggregation type. While category aggregation is set to sum of grades set "drop lowest" to some number. Set some grade items to be extra credit. Check you dont get any errors.
    • Affected Branches:
      MOODLE_21_STABLE, MOODLE_23_STABLE
    • Fixed Branches:
      MOODLE_23_STABLE, MOODLE_24_STABLE
    • Pull 2.4 Branch:
      MDL-29877_bad_grade_item_24
    • Pull Master Branch:
      MDL-29877_bad_grade_item
    • Rank:
      19407

      Description

      When i click Grades in some courses (3 out of 100) i get these errors and then i get memory exhausted:

      Notice: Undefined index: in ../lib/grade/grade_category.php on line 1126 Notice: Trying to get property of non-object in ../lib/grade/grade_category.php on line 1126 Warning: array_key_exists() expects parameter 2 to be array, null given in ../lib/grade/grade_category.php on line 1126 Notice: Undefined property: stdClass::$path in ../lib/grade/grade_category.php on line 1142 Notice: Undefined property: stdClass::$id in /var/www/eclass2/lib/grade/grade_category.php on line 1142 Notice: Undefined property: stdClass::$id in ../lib/grade/grade_category.php on line 1144
      Attempt to obtain a grade_category's associated grade_item without the category's ID being set.

      line 1253 of /lib/grade/grade_category.php: call to debugging()
      line 1241 of /lib/grade/grade_category.php: call to grade_category->get_grade_item()
      line 212 of /lib/grade/grade_category.php: call to grade_category->load_grade_item()
      line 1146 of /lib/grade/grade_category.php: call to grade_category->update()
      line 1019 of /lib/grade/grade_category.php: call to grade_category->get_children()
      line 1646 of /grade/lib.php: call to grade_category::fetch_course_tree()
      line 130 of /grade/report/grader/lib.php: call to grade_tree->grade_tree()
      line 114 of /grade/report/grader/index.php: call to grade_report_grader->__construct()

      Can not regrade non existing category

      line 393 of /lib/grade/grade_category.php: call to debugging()
      line 235 of /lib/grade/grade_category.php: call to grade_category->qualifies_for_regrading()
      line 1146 of /lib/grade/grade_category.php: call to grade_category->update()
      line 1019 of /lib/grade/grade_category.php: call to grade_category->get_children()
      line 1646 of /grade/lib.php: call to grade_category::fetch_course_tree()
      line 130 of /grade/report/grader/lib.php: call to grade_tree->grade_tree()
      line 114 of /grade/report/grader/index.php: call to grade_report_grader->__construct()

      Can not update grade object, no id!

      line 214 of /lib/grade/grade_object.php: call to debugging()
      line 241 of /lib/grade/grade_category.php: call to grade_object->update()
      line 1146 of /lib/grade/grade_category.php: call to grade_category->update()
      line 1019 of /lib/grade/grade_category.php: call to grade_category->get_children()
      line 1646 of /grade/lib.php: call to grade_category::fetch_course_tree()
      line 130 of /grade/report/grader/lib.php: call to grade_tree->grade_tree()
      line 114 of /grade/report/grader/index.php: call to grade_report_grader->__construct()

      PHP Notice: Undefined property: stdClass::$id in ../lib/grade/grade_category.php

      If it helps,we don't use grade categories and all these are set to uncategorised.

        Issue Links

          Activity

          Hide
          Carlos Lopez added a comment -

          We found a possible workaround.

          We noticed that in the table mdl_grade_items, the field "categoryid" was empty for some of the grade items. If you copy the same id that you will find in other items of the same course (search the items by courseid) then the gradebook will work.

          This "categoryid" seems to be the same number that you will find in the field "iteminstance" of the "itemtype" "course".

          Show
          Carlos Lopez added a comment - We found a possible workaround. We noticed that in the table mdl_grade_items, the field "categoryid" was empty for some of the grade items. If you copy the same id that you will find in other items of the same course (search the items by courseid) then the gradebook will work. This "categoryid" seems to be the same number that you will find in the field "iteminstance" of the "itemtype" "course".
          Hide
          Carlos Lopez added a comment -

          One last thing. We think that this might happen when you upgrade a course from one 2.x version to another (we've made all the upgrades at the moment they were released) and maybe the information is stored in different ways from one version to the other.

          Show
          Carlos Lopez added a comment - One last thing. We think that this might happen when you upgrade a course from one 2.x version to another (we've made all the upgrades at the moment they were released) and maybe the information is stored in different ways from one version to the other.
          Hide
          Paul Vaughan added a comment -

          We're seeing this issue in Moodle 2.3.1+ (build 20120816), error report included to show line numbers in this version of Moodle:

          Attempt to obtain a grade_category's associated grade_item without the category's ID being set.

          line 1286 of /lib/grade/grade_category.php: call to debugging()
          line 1272 of /lib/grade/grade_category.php: call to grade_category->get_grade_item()
          line 212 of /lib/grade/grade_category.php: call to grade_category->load_grade_item()
          line 1177 of /lib/grade/grade_category.php: call to grade_category->update()
          line 1053 of /lib/grade/grade_category.php: call to grade_category->get_children()
          line 1805 of /grade/lib.php: call to grade_category::fetch_course_tree()
          line 132 of /grade/report/grader/lib.php: call to grade_tree->grade_tree()
          line 120 of /grade/report/grader/index.php: call to grade_report_grader->__construct()

          Can not regrade non existing category

          line 396 of /lib/grade/grade_category.php: call to debugging()
          line 235 of /lib/grade/grade_category.php: call to grade_category->qualifies_for_regrading()
          line 1177 of /lib/grade/grade_category.php: call to grade_category->update()
          line 1053 of /lib/grade/grade_category.php: call to grade_category->get_children()
          line 1805 of /grade/lib.php: call to grade_category::fetch_course_tree()
          line 132 of /grade/report/grader/lib.php: call to grade_tree->grade_tree()
          line 120 of /grade/report/grader/index.php: call to grade_report_grader->__construct()

          Can not update grade object, no id!

          line 235 of /lib/grade/grade_object.php: call to debugging()
          line 241 of /lib/grade/grade_category.php: call to grade_object->update()
          line 1177 of /lib/grade/grade_category.php: call to grade_category->update()
          line 1053 of /lib/grade/grade_category.php: call to grade_category->get_children()
          line 1805 of /grade/lib.php: call to grade_category::fetch_course_tree()
          line 132 of /grade/report/grader/lib.php: call to grade_tree->grade_tree()
          line 120 of /grade/report/grader/index.php: call to grade_report_grader->__construct()

          This error is repeated 90 times, I'm not sure if this is due to the number of students enrolled onto the course, or the number of possible grades for each student. It only appears to happen for one course as far as we can tell.

          Show
          Paul Vaughan added a comment - We're seeing this issue in Moodle 2.3.1+ (build 20120816), error report included to show line numbers in this version of Moodle: Attempt to obtain a grade_category's associated grade_item without the category's ID being set. line 1286 of /lib/grade/grade_category.php: call to debugging() line 1272 of /lib/grade/grade_category.php: call to grade_category->get_grade_item() line 212 of /lib/grade/grade_category.php: call to grade_category->load_grade_item() line 1177 of /lib/grade/grade_category.php: call to grade_category->update() line 1053 of /lib/grade/grade_category.php: call to grade_category->get_children() line 1805 of /grade/lib.php: call to grade_category::fetch_course_tree() line 132 of /grade/report/grader/lib.php: call to grade_tree->grade_tree() line 120 of /grade/report/grader/index.php: call to grade_report_grader->__construct() Can not regrade non existing category line 396 of /lib/grade/grade_category.php: call to debugging() line 235 of /lib/grade/grade_category.php: call to grade_category->qualifies_for_regrading() line 1177 of /lib/grade/grade_category.php: call to grade_category->update() line 1053 of /lib/grade/grade_category.php: call to grade_category->get_children() line 1805 of /grade/lib.php: call to grade_category::fetch_course_tree() line 132 of /grade/report/grader/lib.php: call to grade_tree->grade_tree() line 120 of /grade/report/grader/index.php: call to grade_report_grader->__construct() Can not update grade object, no id! line 235 of /lib/grade/grade_object.php: call to debugging() line 241 of /lib/grade/grade_category.php: call to grade_object->update() line 1177 of /lib/grade/grade_category.php: call to grade_category->update() line 1053 of /lib/grade/grade_category.php: call to grade_category->get_children() line 1805 of /grade/lib.php: call to grade_category::fetch_course_tree() line 132 of /grade/report/grader/lib.php: call to grade_tree->grade_tree() line 120 of /grade/report/grader/index.php: call to grade_report_grader->__construct() This error is repeated 90 times, I'm not sure if this is due to the number of students enrolled onto the course, or the number of possible grades for each student. It only appears to happen for one course as far as we can tell.
          Hide
          Paul Vaughan added a comment -

          Hi Carlos. I'm looking into your fix for the above problem.

          In the table mdl_grade_items I have 76 rows for the course we are experiencing this issue with. Of these rows, just three have a 'categoryid' value and the rest are null.

          I have just one 'itemtype' of 'course' and its number does match with the existing 'categoryid' values, but I am a little concerned that I'm leaving a lot of null values in there which may cause problems down the road.

          I realise you posted this issue close to a year ago but could you feed back with any more info you may have, and if you were completely successful?

          Cheers,

          Paul.

          Show
          Paul Vaughan added a comment - Hi Carlos. I'm looking into your fix for the above problem. In the table mdl_grade_items I have 76 rows for the course we are experiencing this issue with. Of these rows, just three have a 'categoryid' value and the rest are null. I have just one 'itemtype' of 'course' and its number does match with the existing 'categoryid' values, but I am a little concerned that I'm leaving a lot of null values in there which may cause problems down the road. I realise you posted this issue close to a year ago but could you feed back with any more info you may have, and if you were completely successful? Cheers, Paul.
          Hide
          Willy Lee added a comment -

          I'm a horrible hack, but we ran up against this and I made the assumption that setting it to the first grade_category was better than barfing so I ran the following SQL.

          UPDATE mdl_grade_items g SET categoryid = (SELECT id FROM mdl_grade_categories WHERE `courseid` = g.courseid LIMIT 1) WHERE categoryid IS NULL

          Show
          Willy Lee added a comment - I'm a horrible hack, but we ran up against this and I made the assumption that setting it to the first grade_category was better than barfing so I ran the following SQL. UPDATE mdl_grade_items g SET categoryid = (SELECT id FROM mdl_grade_categories WHERE `courseid` = g.courseid LIMIT 1) WHERE categoryid IS NULL
          Hide
          Willy Lee added a comment -

          So, my fix above caused all kinds of new problems. Apparently, it's important not to blindly set the categoryid for grade_items of itemtype = course

          UPDATE mdl_grade_items g SET categoryid = (SELECT id FROM mdl_grade_categories WHERE `courseid` = g.courseid LIMIT 1) WHERE categoryid IS NULL AND itemtype NOT LIKE 'course'

          Show
          Willy Lee added a comment - So, my fix above caused all kinds of new problems. Apparently, it's important not to blindly set the categoryid for grade_items of itemtype = course UPDATE mdl_grade_items g SET categoryid = (SELECT id FROM mdl_grade_categories WHERE `courseid` = g.courseid LIMIT 1) WHERE categoryid IS NULL AND itemtype NOT LIKE 'course'
          Hide
          Donna Hrynkiw added a comment -

          Moodle 2.2.1+ (Build: 20120223)

          We're experiencing this same issue in two courses (out of approximately 600+), with essentially identical error messages as originally posted.

          Details which may or may not help narrow down the problem:

          • Both courses are taught by the same teacher and have an unusually high (for us) number of assignments and activities: 27 assignments, 35 questionnaires, 1 quiz.
          • The issue/errors follow the course when it is transferred between instances (all the same version of Moodle) via backup/restore.
          • We recently moved from Moodle v1.9 to a fresh, empty instance of Moodle v2.2. It is likely that both courses were restored to the Moodle 2.2 instance from the same Moodle v1.9 archive. I'm awaiting confirmation of this from the teacher.
          Show
          Donna Hrynkiw added a comment - Moodle 2.2.1+ (Build: 20120223) We're experiencing this same issue in two courses (out of approximately 600+), with essentially identical error messages as originally posted. Details which may or may not help narrow down the problem: Both courses are taught by the same teacher and have an unusually high (for us) number of assignments and activities: 27 assignments, 35 questionnaires, 1 quiz. The issue/errors follow the course when it is transferred between instances (all the same version of Moodle) via backup/restore. We recently moved from Moodle v1.9 to a fresh, empty instance of Moodle v2.2. It is likely that both courses were restored to the Moodle 2.2 instance from the same Moodle v1.9 archive. I'm awaiting confirmation of this from the teacher.
          Hide
          Jay Rees added a comment -

          2.3.2 (Build: 20120910)

          We have a problem that seems related so hopefully this will help. I only have a non-scaleable workaround for now.

          Grade book completely not displaying the page – Occurs when categories are left in a “needsupdate” state of 1.

          This happens from two scenarios:

          1) after adjustments are made in the “Categories and Items” view and a category needs to update the total in some way. For example, using the “drop the lowest” or marking items as extra credit or not-extra credit.

          2) while a teacher is entering grades within the grader report (typically for a large/complex grade book).

          It is an infrequent case for courses, but once a course has the problem it seems to reoccur frequently for that particular course.

          Our only solution at this point is to adjust it in the database:

          – A database administrator can update the grades table to change the category needsupdate to 0 to unlock. This may need to be done many times in succession as the category is updated. This is combined with refreshing/resubmitting the grade book change and noting progress on task.

          – Update the needsupdate fields for those IDs (in a list):
          update mdl_grade_items set needsupdate = 0 where courseid = ####;

          – It may be helpful to look for the problem each time and typically it will be the overall course (total) or a sub-category that contains a "drop the lowest" or "extra credit" item. Find the grade items that are in the needsupdate = 1 state:
          select * from mdl_grade_items where courseid = #### and needsupdate = 1 order by sortorder;

          Show
          Jay Rees added a comment - 2.3.2 (Build: 20120910) We have a problem that seems related so hopefully this will help. I only have a non-scaleable workaround for now. Grade book completely not displaying the page – Occurs when categories are left in a “needsupdate” state of 1. This happens from two scenarios: 1) after adjustments are made in the “Categories and Items” view and a category needs to update the total in some way. For example, using the “drop the lowest” or marking items as extra credit or not-extra credit. 2) while a teacher is entering grades within the grader report (typically for a large/complex grade book). It is an infrequent case for courses, but once a course has the problem it seems to reoccur frequently for that particular course. Our only solution at this point is to adjust it in the database: – A database administrator can update the grades table to change the category needsupdate to 0 to unlock. This may need to be done many times in succession as the category is updated. This is combined with refreshing/resubmitting the grade book change and noting progress on task. – Update the needsupdate fields for those IDs (in a list): update mdl_grade_items set needsupdate = 0 where courseid = ####; – It may be helpful to look for the problem each time and typically it will be the overall course (total) or a sub-category that contains a "drop the lowest" or "extra credit" item. Find the grade items that are in the needsupdate = 1 state: select * from mdl_grade_items where courseid = #### and needsupdate = 1 order by sortorder;
          Hide
          Donna Hrynkiw added a comment - - edited

          A work-around until the bug is fixed. Thanks to Carlos and Jay for the tips in their comments.

          mysql> select id,courseid,categoryid,needsupdate from mdl_grade_items where courseid=[CRSID];

          For entries where the categoryid is NULL
          mysql> update mdl_grade_items set categoryid=[CATID] where courseid=[CRSID] and id=[ID];

          Here's what it looked like in our test instance:
          mysql> select id,courseid,categoryid,needsupdate from mdl_grade_items where courseid=3;

          +----+----------+------------+-------------+
          | id | courseid | categoryid | needsupdate |
          +----+----------+------------+-------------+
          | 38 |        3 |       NULL |           1 |
          | 39 |        3 |          3 |           0 |
          | 40 |        3 |          3 |           0 |
          | 41 |        3 |          3 |           0 |
          | 42 |        3 |          3 |           0 |
          | 43 |        3 |          3 |           0 |
          | 44 |        3 |          3 |           0 |
          [pruned]
          | 68 |        3 |          3 |           0 |
          | 69 |        3 |          3 |           0 |
          | 70 |        3 |       NULL |           0 |   <----
          | 71 |        3 |       NULL |           0 |   <----
          | 72 |        3 |       NULL |           0 |   <----
          +----+----------+------------+-------------+
          35 rows in set (0.01 sec)
          

          mysql> update mdl_grade_items set categoryid=3 where courseid=3 and id=70;
          repeat for ids 71 and 72

          Moodle 2.3.2 (Build: 20120910)

          Show
          Donna Hrynkiw added a comment - - edited A work-around until the bug is fixed. Thanks to Carlos and Jay for the tips in their comments. mysql> select id,courseid,categoryid,needsupdate from mdl_grade_items where courseid= [CRSID] ; For entries where the categoryid is NULL mysql> update mdl_grade_items set categoryid= [CATID] where courseid= [CRSID] and id= [ID] ; Here's what it looked like in our test instance: mysql> select id,courseid,categoryid,needsupdate from mdl_grade_items where courseid=3; +----+----------+------------+-------------+ | id | courseid | categoryid | needsupdate | +----+----------+------------+-------------+ | 38 | 3 | NULL | 1 | | 39 | 3 | 3 | 0 | | 40 | 3 | 3 | 0 | | 41 | 3 | 3 | 0 | | 42 | 3 | 3 | 0 | | 43 | 3 | 3 | 0 | | 44 | 3 | 3 | 0 | [pruned] | 68 | 3 | 3 | 0 | | 69 | 3 | 3 | 0 | | 70 | 3 | NULL | 0 | <---- | 71 | 3 | NULL | 0 | <---- | 72 | 3 | NULL | 0 | <---- +----+----------+------------+-------------+ 35 rows in set (0.01 sec) mysql> update mdl_grade_items set categoryid=3 where courseid=3 and id=70; repeat for ids 71 and 72 Moodle 2.3.2 (Build: 20120910)
          Hide
          Donna Hrynkiw added a comment -

          My apologies for the spammage. I didn't find the edit/preview button until... well, later than I should've.

          Show
          Donna Hrynkiw added a comment - My apologies for the spammage. I didn't find the edit/preview button until... well, later than I should've.
          Hide
          Johan Reinalda added a comment -

          We also see this, running 2.3.3+ (20121214).
          This site was a new install of 2.3.2 (release), later upgraded to 2.3.3, and then 2.3.3+ 20121130 and 20121214

          Will test this database fix in dev, but would be nice to have code fix.

          Johan

          Show
          Johan Reinalda added a comment - We also see this, running 2.3.3+ (20121214). This site was a new install of 2.3.2 (release), later upgraded to 2.3.3, and then 2.3.3+ 20121130 and 20121214 Will test this database fix in dev, but would be nice to have code fix. Johan
          Hide
          Chris Follin added a comment -

          We're seeing this in 2.3.3, too.

          Show
          Chris Follin added a comment - We're seeing this in 2.3.3, too.
          Hide
          Thelma Polanco-Perez added a comment -

          We experienced the same issue in 2.3.3+ few days ago.
          Thanks to Donna and Jay for posting a workaround.
          It worked for us!

          Show
          Thelma Polanco-Perez added a comment - We experienced the same issue in 2.3.3+ few days ago. Thanks to Donna and Jay for posting a workaround. It worked for us!
          Hide
          Andrew Davis added a comment - - edited

          Looking at the code involved in this call stack I noticed something interesting.

          line 1253 of /lib/grade/grade_category.php: call to debugging()
          line 1241 of /lib/grade/grade_category.php: call to grade_category->get_grade_item()
          line 212 of /lib/grade/grade_category.php: call to grade_category->load_grade_item()
          line 1146 of /lib/grade/grade_category.php: call to grade_category->update()
          line 1019 of /lib/grade/grade_category.php: call to grade_category->get_children()

          This is what's in get_children()

          if (empty($cat->parent)) {
          
              if ($cat->path !== '/'.$cat->id.'/') {
                  $grade_category = new grade_category($cat, false);
                  $grade_category->path  = '/'.$cat->id.'/';
                  $grade_category->depth = 1;
                  $grade_category->update('system');
                  return $this->get_children($include_category_items);
              }
          
          }
          

          We're creating a grade category object and not setting an ID. The false passed into the constructor means not to go to the database to load the rest of the object's data.

          Later within that update() call is this

          if (empty($this->id)) {
              debugging("Attempt to obtain a grade_category's associated grade_item without the category's ID being set.");
              return false;
          }
          

          So if we encounter a category within the course with an empty parent but which has a path other than what the course category should have we create a grade category object that is doomed to fail.

          I'm not yet entirely sure of what we're even trying to do here creating this grade category object. It seems like a bad thing to add a second course level category. Maybe this is an attempt to fix a somehow broken course category.

          That structure in get_children() dates back to 2008 so it's not something newly added.

          Show
          Andrew Davis added a comment - - edited Looking at the code involved in this call stack I noticed something interesting. line 1253 of /lib/grade/grade_category.php: call to debugging() line 1241 of /lib/grade/grade_category.php: call to grade_category->get_grade_item() line 212 of /lib/grade/grade_category.php: call to grade_category->load_grade_item() line 1146 of /lib/grade/grade_category.php: call to grade_category->update() line 1019 of /lib/grade/grade_category.php: call to grade_category->get_children() This is what's in get_children() if (empty($cat->parent)) { if ($cat->path !== '/'.$cat->id.'/') { $grade_category = new grade_category($cat, false ); $grade_category->path = '/'.$cat->id.'/'; $grade_category->depth = 1; $grade_category->update('system'); return $ this ->get_children($include_category_items); } } We're creating a grade category object and not setting an ID. The false passed into the constructor means not to go to the database to load the rest of the object's data. Later within that update() call is this if (empty($ this ->id)) { debugging( "Attempt to obtain a grade_category's associated grade_item without the category's ID being set." ); return false ; } So if we encounter a category within the course with an empty parent but which has a path other than what the course category should have we create a grade category object that is doomed to fail. I'm not yet entirely sure of what we're even trying to do here creating this grade category object. It seems like a bad thing to add a second course level category. Maybe this is an attempt to fix a somehow broken course category. That structure in get_children() dates back to 2008 so it's not something newly added.
          Hide
          Andrew Davis added a comment -

          I'm adding a potential fix.

          I would really love it if someone who is experiencing this issue could see if this small code change fixes it for them. Don't introduce this change on your production system so you'll want some sort of development copy.

          This change is very simple and I think it makes sense. It doesn't break any unit tests however the code within the "if ($cat->path !== '/'.$cat->id.'/')" is never executed by the unit tests so I can't rely on them.

          Show
          Andrew Davis added a comment - I'm adding a potential fix. I would really love it if someone who is experiencing this issue could see if this small code change fixes it for them. Don't introduce this change on your production system so you'll want some sort of development copy. This change is very simple and I think it makes sense. It doesn't break any unit tests however the code within the "if ($cat->path !== '/'.$cat->id.'/')" is never executed by the unit tests so I can't rely on them.
          Hide
          Charles Fulton added a comment -

          I should be able to test this in the next day or two; could you take a quick look at MDL-37676?

          Show
          Charles Fulton added a comment - I should be able to test this in the next day or two; could you take a quick look at MDL-37676 ?
          Hide
          Charles Fulton added a comment -

          I've tested this with known bad data (generated from MDL-37672) and I'm still getting a stack trace:

          Notice: Undefined index: in ../lib/grade/grade_category.php on line 1160 Notice: Trying to get property of non-object in ../lib/grade/grade_category.php on line 1160 Warning: array_key_exists() expects parameter 2 to be array, null given in ..lib/grade/grade_category.php on line 1160 Notice: Undefined property: stdClass::$path in ../lib/grade/grade_category.php on line 1176 Notice: Undefined property: stdClass::$id in ../lib/grade/grade_category.php on line 1176 Notice: Undefined property: stdClass::$id in ../lib/grade/grade_category.php on line 1178 Notice: Undefined property: stdClass::$id in ../lib/grade/grade_category.php on line 1179

          Attempt to obtain a grade_category's associated grade_item without the category's ID being set.
          line 1290 of /lib/grade/grade_category.php: call to debugging()
          line 1276 of /lib/grade/grade_category.php: call to grade_category->get_grade_item()
          line 212 of /lib/grade/grade_category.php: call to grade_category->load_grade_item()
          line 1181 of /lib/grade/grade_category.php: call to grade_category->update()
          line 1056 of /lib/grade/grade_category.php: call to grade_category->get_children()
          line 1841 of /grade/lib.php: call to grade_category::fetch_course_tree()
          line 132 of /grade/report/grader/lib.php: call to grade_tree->grade_tree()
          line 120 of /grade/report/grader/index.php: call to grade_report_grader->__construct()
          Can not regrade non existing category
          line 396 of /lib/grade/grade_category.php: call to debugging()
          line 235 of /lib/grade/grade_category.php: call to grade_category->qualifies_for_regrading()
          line 1181 of /lib/grade/grade_category.php: call to grade_category->update()
          line 1056 of /lib/grade/grade_category.php: call to grade_category->get_children()
          line 1841 of /grade/lib.php: call to grade_category::fetch_course_tree()
          line 132 of /grade/report/grader/lib.php: call to grade_tree->grade_tree()
          line 120 of /grade/report/grader/index.php: call to grade_report_grader->__construct()
          Can not update grade object, no id!
          line 235 of /lib/grade/grade_object.php: call to debugging()
          line 241 of /lib/grade/grade_category.php: call to grade_object->update()
          line 1181 of /lib/grade/grade_category.php: call to grade_category->update()
          line 1056 of /lib/grade/grade_category.php: call to grade_category->get_children()
          line 1841 of /grade/lib.php: call to grade_category::fetch_course_tree()
          line 132 of /grade/report/grader/lib.php: call to grade_tree->grade_tree()
          line 120 of /grade/report/grader/index.php: call to grade_report_grader->__construct()
          
          Show
          Charles Fulton added a comment - I've tested this with known bad data (generated from MDL-37672 ) and I'm still getting a stack trace: Notice: Undefined index: in ../lib/grade/grade_category.php on line 1160 Notice: Trying to get property of non-object in ../lib/grade/grade_category.php on line 1160 Warning: array_key_exists() expects parameter 2 to be array, null given in ..lib/grade/grade_category.php on line 1160 Notice: Undefined property: stdClass::$path in ../lib/grade/grade_category.php on line 1176 Notice: Undefined property: stdClass::$id in ../lib/grade/grade_category.php on line 1176 Notice: Undefined property: stdClass::$id in ../lib/grade/grade_category.php on line 1178 Notice: Undefined property: stdClass::$id in ../lib/grade/grade_category.php on line 1179 Attempt to obtain a grade_category's associated grade_item without the category's ID being set. line 1290 of /lib/grade/grade_category.php: call to debugging() line 1276 of /lib/grade/grade_category.php: call to grade_category->get_grade_item() line 212 of /lib/grade/grade_category.php: call to grade_category->load_grade_item() line 1181 of /lib/grade/grade_category.php: call to grade_category->update() line 1056 of /lib/grade/grade_category.php: call to grade_category->get_children() line 1841 of /grade/lib.php: call to grade_category::fetch_course_tree() line 132 of /grade/report/grader/lib.php: call to grade_tree->grade_tree() line 120 of /grade/report/grader/index.php: call to grade_report_grader->__construct() Can not regrade non existing category line 396 of /lib/grade/grade_category.php: call to debugging() line 235 of /lib/grade/grade_category.php: call to grade_category->qualifies_for_regrading() line 1181 of /lib/grade/grade_category.php: call to grade_category->update() line 1056 of /lib/grade/grade_category.php: call to grade_category->get_children() line 1841 of /grade/lib.php: call to grade_category::fetch_course_tree() line 132 of /grade/report/grader/lib.php: call to grade_tree->grade_tree() line 120 of /grade/report/grader/index.php: call to grade_report_grader->__construct() Can not update grade object, no id! line 235 of /lib/grade/grade_object.php: call to debugging() line 241 of /lib/grade/grade_category.php: call to grade_object->update() line 1181 of /lib/grade/grade_category.php: call to grade_category->update() line 1056 of /lib/grade/grade_category.php: call to grade_category->get_children() line 1841 of /grade/lib.php: call to grade_category::fetch_course_tree() line 132 of /grade/report/grader/lib.php: call to grade_tree->grade_tree() line 120 of /grade/report/grader/index.php: call to grade_report_grader->__construct()
          Hide
          Andrew Davis added a comment -

          Hi Charles. Is there any chance you're able to send me the backup you're using to create the data that's causing this? It should not contain any actual student personal information ie no student names, email addresses etc.

          If that's possible could you either attach it here if its something you're happy to have be publicly available. Alternatively you can email it to me at andrew@moodle.com.

          I don't currently have a 1.9 site set up. If I can't get the backup from you let me know and I'll get one installed and populated.

          Show
          Andrew Davis added a comment - Hi Charles. Is there any chance you're able to send me the backup you're using to create the data that's causing this? It should not contain any actual student personal information ie no student names, email addresses etc. If that's possible could you either attach it here if its something you're happy to have be publicly available. Alternatively you can email it to me at andrew@moodle.com. I don't currently have a 1.9 site set up. If I can't get the backup from you let me know and I'll get one installed and populated.
          Hide
          Charles Fulton added a comment -

          Hi Andy, sorry for the delay. I've attached the same backup I provided for MDL-37676. This is a 1.9 course but restored into 2+ it'll cause the issue.

          Show
          Charles Fulton added a comment - Hi Andy, sorry for the delay. I've attached the same backup I provided for MDL-37676 . This is a 1.9 course but restored into 2+ it'll cause the issue.
          Hide
          Andrew Davis added a comment -

          Thanks Charles. I can see the problem now.

          Show
          Andrew Davis added a comment - Thanks Charles. I can see the problem now.
          Hide
          Andrew Davis added a comment -

          I think I have a fix for this. MDL-37676 is fixing the restore process and will stop bad grade items getting into the system in the first place.

          I'm just writing some upgrade code to fix existing bad grade items and adding a safety check here and there to make the code involved less brittle.

          Show
          Andrew Davis added a comment - I think I have a fix for this. MDL-37676 is fixing the restore process and will stop bad grade items getting into the system in the first place. I'm just writing some upgrade code to fix existing bad grade items and adding a safety check here and there to make the code involved less brittle.
          Hide
          Jason Fowler added a comment -

          [Y] Syntax
          [Y] Output
          [Y] Whitespace
          [-] Language
          [Y] Databases
          [Y] Testing
          [-] Security
          [-] Documentation
          [Y] Git
          [Y] Sanity check

          Show
          Jason Fowler added a comment - [Y] Syntax [Y] Output [Y] Whitespace [-] Language [Y] Databases [Y] Testing [-] Security [-] Documentation [Y] Git [Y] Sanity check
          Hide
          Jason Fowler added a comment -

          Just noticed lib/grade/grade_category.php has the line //debugging("$sortorder exists in item loop");

          while that isn't part of your patch, it might be worth cleaning it up anyway.

          Show
          Jason Fowler added a comment - Just noticed lib/grade/grade_category.php has the line //debugging("$sortorder exists in item loop"); while that isn't part of your patch, it might be worth cleaning it up anyway.
          Hide
          Andrew Davis added a comment -

          I've removed that commented out code and created version branches. Putting this up for integration.

          Show
          Andrew Davis added a comment - I've removed that commented out code and created version branches. Putting this up for integration.
          Hide
          Damyon Wiese added a comment -

          Thanks Andrew, this has been integrated to 23, 24 and master now.

          Please note I had to fix whitespace errors on the backport branches - please check your editor settings.

          Also - more feedback:
          When splitting control statements into multiple lines, the extra lines should have and extra indentation level so they don't line up with the code in the block.

          E.g.

          if ($a &&
                  $b) {
              // do something
          

          Not

          if ($a &&
              $b) {
              // do something
          

          (Very minor)

          Show
          Damyon Wiese added a comment - Thanks Andrew, this has been integrated to 23, 24 and master now. Please note I had to fix whitespace errors on the backport branches - please check your editor settings. Also - more feedback: When splitting control statements into multiple lines, the extra lines should have and extra indentation level so they don't line up with the code in the block. E.g. if ($a && $b) { // do something Not if ($a && $b) { // do something (Very minor)
          Hide
          Damyon Wiese added a comment -

          And an extra fix had to be added to all branches to remove the hardcoded mdl_prefix from the upgrade step (Grr...)

          Show
          Damyon Wiese added a comment - And an extra fix had to be added to all branches to remove the hardcoded mdl_prefix from the upgrade step (Grr...)
          Hide
          Andrew Davis added a comment -

          Thanks for that Damyon. Very sloppy of me

          Show
          Andrew Davis added a comment - Thanks for that Damyon. Very sloppy of me
          Hide
          Jason Fowler added a comment -

          And me too, I should have picked that up in peer review, sorry guys.

          Show
          Jason Fowler added a comment - And me too, I should have picked that up in peer review, sorry guys.
          Hide
          Ankit Agarwal added a comment -

          Discovered MDL-39123 while testing this.

          Show
          Ankit Agarwal added a comment - Discovered MDL-39123 while testing this.
          Hide
          Ankit Agarwal added a comment -

          works as described.
          Thanks

          Show
          Ankit Agarwal added a comment - works as described. Thanks
          Hide
          Dan Poltawski added a comment -

          Blooming Marvelous! It's time for a knees up - your changes are upstream!

          Thanks for making Moodle better!

          Toodle pip

          Show
          Dan Poltawski added a comment - Blooming Marvelous! It's time for a knees up - your changes are upstream! Thanks for making Moodle better! Toodle pip

            People

            • Votes:
              20 Vote for this issue
              Watchers:
              21 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: