{"id":167,"date":"2026-03-23T16:41:01","date_gmt":"2026-03-23T20:41:01","guid":{"rendered":"https:\/\/huckleberry.mhu.edu\/randommusings\/?p=167"},"modified":"2026-03-24T08:12:05","modified_gmt":"2026-03-24T12:12:05","slug":"moodle-gradebook-error-attempt-to-assign-property-sortorder-on-null","status":"publish","type":"post","link":"https:\/\/huckleberry.mhu.edu\/randommusings\/index.php\/2026\/03\/23\/moodle-gradebook-error-attempt-to-assign-property-sortorder-on-null\/","title":{"rendered":"Moodle Gradebook Error: Attempt to assign property &#8220;sortorder&#8221; on null&#8217;"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\">The Musing<\/h2>\n\n\n\n<p>I had a faculty member contact me and let me know that when they clicked the &#8216;Grades&#8217; heading in Moodle (5.0.4+), they got an exception: Attempt to assign property &#8220;sortorder&#8221; on null&#8217;. Big red exception, with no helpful message. The best they could tell me was that they were adjusting weights and adding grade items. Hmm&#8230;doesn&#8217;t sound terribly &#8220;dangerous&#8221;, does it?<\/p>\n\n\n\n<p>I looked at the logs quite a bit, and noticed they had deleted some categories, too. Strangely, the name of the category was &#8221; &#8211; also odd.<\/p>\n\n\n\n<p>According to this forum post on Moodle.org, a grade item was in a grade category that didn&#8217;t exist. That&#8217;s got to be hard to do, right?<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">The Fix<\/h2>\n\n\n\n<p>I decided to see if the forum post was correct. Digging around in the Moodle DB, I decided to match up all of the grade items with their corresponding categories to see if there were any that was in a nonexistent category. <\/p>\n\n\n\n<p>I used this SQL to see if anything was missing (courseid was 12456):<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>      SELECT item.id,left(itemname,10) as name,itemtype,fullname AS catname\n        FROM mdl_grade_items AS item \n   LEFT JOIN mdl_grade_categories AS cat\n          ON categoryid=cat.id \n       WHERE itemtype!='course'\n         AND itemtype!='category'\n         AND item.courseid=12456;\n<\/code><\/pre>\n\n\n\n<p>The output was something like:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>+--------+------------+----------+------------------------------+\n| id     | name       | itemtype | catname                      |\n+--------+------------+----------+------------------------------+\n| 159125 | Syllabus Q | mod      | Journal \/ Forum \/ Quizes     |\n| 159993 | Chapter 4  | mod      | Journal \/ Forum \/ Quizes     |\n| 160213 | Icebreaker | manual   | Journal \/ Forum \/ Quizes     |\n| 160214 | Anatomy of | manual   | Journal \/ Forum \/ Quizes     |\n| 160374 | Group Time | mod      | Group Timeline Project       |\n| 160387 | Playwright | mod      | Playwright Presentation      |\n| 160422 | Kendrick C | mod      | Journal \/ Forum \/ Quizes     |\n| 160658 | Week 4 Qui | mod      | Journal \/ Forum \/ Quizes     |\n| 160679 | Julius Cae | mod      | Study Guide 1, Julius Caesar |\n| 160680 | Group Time | mod      | Group Timeline Project       |\n| 160770 | Julius Cae | manual   | Journal \/ Forum \/ Quizes     |\n| 161005 | Week 5 Qui | mod      | Journal \/ Forum \/ Quizes     |\n| 161006 | Julius Cae | mod      | Study Guide 1, Julius Caesar |\n| 161167 | Week 6 Qui | mod      | Journal \/ Forum \/ Quizes     |\n| 161319 | Week 7 Sli | mod      | Journal \/ Forum \/ Quizes     |\n| 161517 | Julius Cae | mod      | Study Guide 1, Julius Caesar |\n| 161518 | Playwright | mod      | Playwright Presentation      |\n+--------+------------+----------+------------------------------+<\/code><\/pre>\n\n\n\n<p>Notice in the &#8216;catname&#8217; column, every item seems to have a valid category name. Hmm&#8230;doesn&#8217;t seem like we have the same problem as the poster from the Moodle forums.<\/p>\n\n\n\n<p>Next, I started looking at the categories themselves. Was something screwy about them? Remember, from the logs, I did notice that the instructor had deleted a category just before emailing me.<\/p>\n\n\n\n<p>I tried to match up all the grade items that were categories with their detail from the mdl_grade_categories table using this SQL:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>       SELECT items.id,iteminstance,fullname\n         FROM mdl_grade_items AS items\n    LEFT JOIN mdl_grade_categories AS cats\n           ON items.iteminstance=cats.id\n        WHERE items.courseid=12456\n          AND itemtype='category';<\/code><\/pre>\n\n\n\n<p>This gave me a more interesting result:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>+--------+--------------+------------------------------+\n| id     | iteminstance | fullname                     |\n+--------+--------------+------------------------------+\n| 160211 |        25608 | Journal \/ Forum \/ Quizes     |\n| 160375 |        25626 | Group Timeline Project       |\n| 160767 |        25745 | Study Guide 1, Julius Caesar |\n| 160768 |        25746 | Playwright Presentation      |\n| 161884 |        25609 | NULL                         |\n| 161885 |        25866 | Two Group Plays              |\n+--------+--------------+------------------------------+<\/code><\/pre>\n\n\n\n<p>Aha! Look at that suspect row with id 161884. NULL for the fullname? Looking at the mdl_grade_categories table, I found this:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>SELECT * FROM mdl_grade_categories WHERE id=25609;\nEmpty set (0.000 sec)<\/code><\/pre>\n\n\n\n<p>Now we have it. There is a grade item (id 161884) that is a category, and the corresponding entry in the grade_categories table (id 25609) doesn&#8217;t exist! I bet that will cause issues.<\/p>\n\n\n\n<p>I searched back through all of the other grade categories for course 12456, to make sure the category 25609 isn&#8217;t referenced in the path or parent fields:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>     SELECT id,parent,path\n       FROM mdl_grade_categories\n      WHERE courseid=12456;<\/code><\/pre>\n\n\n\n<p>Result:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>+-------+--------+---------------+\n| id    | parent | path          |\n+-------+--------+---------------+\n| 25081 |   NULL | \/25081\/       |\n| 25608 |  25081 | \/25081\/25608\/ |\n| 25626 |  25081 | \/25081\/25626\/ |\n| 25745 |  25081 | \/25081\/25745\/ |\n| 25746 |  25081 | \/25081\/25746\/ |\n| 25866 |  25081 | \/25081\/25866\/ |\n+-------+--------+---------------+\n<\/code><\/pre>\n\n\n\n<p>Nope. No 25609 anywhere. I did something similar with the grade_items table:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>     SELECT id,categoryid,itemtype,iteminstance\n       FROM mdl_grade_items\n      WHERE courseid=12456;<\/code><\/pre>\n\n\n\n<p>Result:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>+--------+------------+----------+--------------+\n| id     | categoryid | itemtype | iteminstance |\n+--------+------------+----------+--------------+\n| 156813 |       NULL | course   |        25081 |\n| 159125 |      25608 | mod      |        17226 |\n| 159993 |      25608 | mod      |        17375 |\n| 160211 |       NULL | category |        25608 |\n| 160213 |      25608 | manual   |         NULL |\n| 160214 |      25608 | manual   |         NULL |\n| 160374 |      25626 | mod      |        73528 |\n| 160375 |       NULL | category |        25626 |\n| 160387 |      25746 | mod      |        73537 |\n| 160422 |      25608 | mod      |        17396 |\n| 160658 |      25608 | mod      |        17410 |\n| 160679 |      25745 | mod      |        73634 |\n| 160680 |      25626 | mod      |        73635 |\n| 160767 |       NULL | category |        25745 |\n| 160768 |       NULL | category |        25746 |\n| 160770 |      25608 | manual   |         NULL |\n| 161005 |      25608 | mod      |        17457 |\n| 161006 |      25745 | mod      |        73773 |\n| 161167 |      25608 | mod      |        17468 |\n| 161319 |      25608 | mod      |        17480 |\n| 161517 |      25745 | mod      |        74042 |\n| 161518 |      25746 | mod      |        74043 |\n| 161884 |       NULL | category |        25609 |\n| 161885 |       NULL | category |        25866 |\n+--------+------------+----------+--------------+\n<\/code><\/pre>\n\n\n\n<p>I couldn&#8217;t find any occurrences of 25609 other than the row with id 161884. So &#8211; this is on a test site, mind you &#8211; I decided to delete the entry from mdl_grade_items!<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>     DELETE FROM mdl_grade_items \n           WHERE id=161884;<\/code><\/pre>\n\n\n\n<p>I refreshed the grades pages and voil\u00e0! The nasty red error was gone. I had to recalculate the grades &#8211; wonder if that was somehow a contributing factor &#8211; but then everything showed up as it should. <\/p>\n\n\n\n<p>I replicated my steps on the live site, held my breath, deleted the row, and had the same result.<\/p>\n\n\n\n<p>I&#8217;m not sure why the category wasn&#8217;t deleted cleanly (or wasn&#8217;t created cleanly?), but it seems to be working now, with no ill effects. <\/p>\n","protected":false},"excerpt":{"rendered":"<p>The Musing I had a faculty member contact me and let me know that when they clicked the &#8216;Grades&#8217; heading in Moodle (5.0.4+), they got an exception: Attempt to assign property &#8220;sortorder&#8221; on null&#8217;. Big red exception, with no helpful message. The best they could tell me was that they were adjusting weights and adding grade items. Hmm&#8230;doesn&#8217;t sound terribly&hellip; <a href=\"https:\/\/huckleberry.mhu.edu\/randommusings\/index.php\/2026\/03\/23\/moodle-gradebook-error-attempt-to-assign-property-sortorder-on-null\/\">More &rarr;<\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6],"tags":[],"class_list":["post-167","post","type-post","status-publish","format-standard","hentry","category-moodle"],"_links":{"self":[{"href":"https:\/\/huckleberry.mhu.edu\/randommusings\/index.php\/wp-json\/wp\/v2\/posts\/167","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/huckleberry.mhu.edu\/randommusings\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/huckleberry.mhu.edu\/randommusings\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/huckleberry.mhu.edu\/randommusings\/index.php\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/huckleberry.mhu.edu\/randommusings\/index.php\/wp-json\/wp\/v2\/comments?post=167"}],"version-history":[{"count":9,"href":"https:\/\/huckleberry.mhu.edu\/randommusings\/index.php\/wp-json\/wp\/v2\/posts\/167\/revisions"}],"predecessor-version":[{"id":177,"href":"https:\/\/huckleberry.mhu.edu\/randommusings\/index.php\/wp-json\/wp\/v2\/posts\/167\/revisions\/177"}],"wp:attachment":[{"href":"https:\/\/huckleberry.mhu.edu\/randommusings\/index.php\/wp-json\/wp\/v2\/media?parent=167"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/huckleberry.mhu.edu\/randommusings\/index.php\/wp-json\/wp\/v2\/categories?post=167"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/huckleberry.mhu.edu\/randommusings\/index.php\/wp-json\/wp\/v2\/tags?post=167"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}