Uploaded image for project: 'Moodle'
  1. Moodle
  2. MDL-51694

Deleting user causes exception when a grade_grades row has no corresponding grade_items row

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: Minor Minor
    • 3.7.6, 3.8.3
    • 2.9.2, 3.1.9, 3.2.1, 3.2.3, 3.2.6, 3.3.3, 3.4, 3.5.10, 3.6.8, 3.7.4, 3.7.5, 3.8.1, 3.8.2, 3.9
    • Gradebook
    • MOODLE_29_STABLE, MOODLE_31_STABLE, MOODLE_32_STABLE, MOODLE_33_STABLE, MOODLE_34_STABLE, MOODLE_35_STABLE, MOODLE_36_STABLE, MOODLE_37_STABLE, MOODLE_38_STABLE, MOODLE_39_STABLE
    • MOODLE_37_STABLE, MOODLE_38_STABLE
    • Hide

      Manually delete orphaned records in grade_grades

      Show
      Manually delete orphaned records in grade_grades
    • Hide
      1. Execute the following database query and write down the number you get returned.

        SELECT COUNT(*) FROM mdl_grade_grades WHERE itemid NOT IN (SELECT id FROM mdl_grade_items)
        

      2. Go to  Site administration > Development > Make test course and create a medium size course (or any course with more than 1000 participants).
      3. While still in admin, go to "Users" > "Browse list of users" and find a user with an email like tool_generator_xxx.
      4. Edit that account so the password is 'test'. Remember the username, well need it later.
      5. Go to the course and create a new grade item called "Test grade item" in this course (grades -> setup -> add grade item - near the bottom).
      6. Export grades:
        • Grades -> export -> plain text file -> download
        • Only select the single grade item which you created prior to this. There are controls near the bottom of the page to deselect all.
      7. Now, import the exported grades (Grades -> import -> CSV file -> upload grades)
        • Upload the file you just exported, and click next
        • Under the "Identify user by" section of the form, set "Map from" to ID number and "Map to" to the same
        • Under the "Grade item mappings" section of the form, near the bottom, set the mapping for "Test grade item (Real)" to "Test grade item"
        • Click "Upload grades" and wait for it to finish the upload.
      8. Open another browser and log in as a student who is enrolled in the course. Go to the course home page. Make sure you can easily access both browser sessions as timing is crucial for the next part.
      9. These steps need to be performed one after another in quick succession, so read first, then perform:
        • As a teacher, delete the grade item.
        • As the student in the other browser, while Moodle is deleting the grades (which takes some seconds), go to the gradebook.
      10. Execute the query from step 1 again.
      11. Confirm the query returns the same number as in step 1.
      Show
      Execute the following database query and write down the number you get returned. SELECT COUNT(*) FROM mdl_grade_grades WHERE itemid NOT IN (SELECT id FROM mdl_grade_items) Go to  Site administration > Development > Make test course and create a medium size course (or any course with more than 1000 participants). While still in admin, go to "Users" > "Browse list of users" and find a user with an email like tool_generator_xxx. Edit that account so the password is 'test'. Remember the username, well need it later. Go to the course and create a new grade item called "Test grade item" in this course (grades -> setup -> add grade item - near the bottom). Export grades: Grades -> export -> plain text file -> download Only select the single grade item which you created prior to this. There are controls near the bottom of the page to deselect all. Now, import the exported grades (Grades -> import -> CSV file -> upload grades) Upload the file you just exported, and click next Under the "Identify user by" section of the form, set "Map from" to ID number and "Map to" to the same Under the "Grade item mappings" section of the form, near the bottom, set the mapping for "Test grade item (Real)" to "Test grade item" Click "Upload grades" and wait for it to finish the upload. Open another browser and log in as a student who is enrolled in the course. Go to the course home page. Make sure you can easily access both browser sessions as timing is crucial for the next part. These steps need to be performed one after another in quick succession, so read first, then perform: As a teacher, delete the grade item. As the student in the other browser, while Moodle is deleting the grades (which takes some seconds), go to the gradebook. Execute the query from step 1 again. Confirm the query returns the same number as in step 1.

      I cannot delete some users. When I try I get an error page saying "Can not find data record in database table course." Here are the error_log entries:

      [Wed Oct 07 14:10:19 2015] [error] [client 143.195.4.8] PHP Notice:  Trying to get property of non-object in /srv/www/courses.imsa.edu/moodleC/lib/grade/grade_grade.php on line 1067, referer: http://moodlec.devnet.imsa.edu/admin/user.php?sort=name&dir=ASC&perpage=30&page=0&delete=2973&sesskey=IhIWmH8Y9H
      [Wed Oct 07 14:10:19 2015] [error] [client 143.195.4.8] PHP Notice:  Trying to get property of non-object in /srv/www/courses.imsa.edu/moodleC/lib/classes/event/grade_deleted.php on line 70, referer: http://moodlec.devnet.imsa.edu/admin/user.php?sort=name&dir=ASC&perpage=30&page=0&delete=2973&sesskey=IhIWmH8Y9H
      [Wed Oct 07 14:10:19 2015] [error] [client 143.195.4.8] Default exception handler: Can not find data record in database table course. Debug: SELECT id,category FROM {course} WHERE id IS NULL\n[array (\n)]\nError code: invalidrecord\n* line 1453 of /lib/dml/moodle_database.php: dml_missing_record_exception thrown\n* line 1429 of /lib/dml/moodle_database.php: call to moodle_database->get_record_select()\n* line 6884 of /lib/accesslib.php: call to moodle_database->get_record()\n* line 70 of /lib/classes/event/grade_deleted.php: call to context_course::instance()\n* line 1026 of /lib/grade/grade_grade.php: call to core\\event\\grade_deleted::create_from_grade()\n* line 1335 of /lib/gradelib.php: call to grade_grade->delete()\n* line 3944 of /lib/moodlelib.php: call to grade_user_delete()\n* line 86 of /admin/user.php: call to delete_user()\n, referer: http://moodlec.devnet.imsa.edu/admin/user.php?sort=name&dir=ASC&perpage=30&page=0&delete=2973&sesskey=IhIWmH8Y9H
      

      I find that the problem arises for users that have grade_grades rows for which there is no associated grade_items row. Out of 113021 rows in grade_grades, 5374 of them have itemid column value for which there is no grade_item row with that id column value. I have no idea why that is the case in our data or how to replicate it.

            mgauk Martin Gauk
            fredcy Fred Yankowski
            Simey Lameze Simey Lameze
            Jake Dallimore Jake Dallimore
            Eloy Lafuente (stronk7) Eloy Lafuente (stronk7)
            Votes:
            21 Vote for this issue
            Watchers:
            31 Start watching this issue

              Created:
              Updated:
              Resolved:

                Estimated:
                Original Estimate - 0 minutes
                0m
                Remaining:
                Remaining Estimate - 0 minutes
                0m
                Logged:
                Time Spent - 1 day, 2 hours
                1d 2h

                  Error rendering 'clockify-timesheets-time-tracking-reports:timer-sidebar'. Please contact your Jira administrators.