"Found more than one record in fetch()" on lesson completion

"Found more than one record in fetch()" on lesson completion

by Stewart Law -
Number of replies: 0

I'm having some problems with Moodles lesson completion. When the first student completes a lesson the process appear to work correctly, the student presses the final navigation button at the end of the lesson and is presented with the "Congratulations - end of lesson reached" page. However when the 2nd, 3rd, 4th, etc student completes the lesson they are presented with "Found more than one record in fetch() !" and this is happening with every course.

With debugging enable I can see the following:

Debug info:
Error code: morethanonerecordinfetch
Stack trace:
  • line 496 of /lib/setuplib.php: moodle_exception thrown
  • line 169 of /lib/grade/grade_object.php: call to print_error()
  • line 354 of /lib/grade/grade_item.php: call to grade_object::fetch_helper()
  • line 1125 of /lib/grade/grade_item.php: call to grade_item::fetch()
  • line 2015 of /lib/grade/grade_item.php: call to grade_item::fetch_course_item()
  • line 294 of /lib/gradelib.php: call to grade_item->update_raw_grade()
  • line 814 of /mod/lesson/lib.php: call to grade_update()
  • line 734 of /mod/lesson/lib.php: call to lesson_grade_item_update()
  • line 589 of /mod/lesson/view.php: call to lesson_update_grades()
After stepping through the code it looks like Moodle is trying to load a single row of data from the "mdl_grade_items" database table, which is fine for the first user because as expected only 1 row matching the course id and itemtype "course" exists. However after the first user completes the course a random number of rows appear to be inserted into the database table (typically 4 to 6 rows) and this causes the above error to be thrown for any additional completions. The following code is triggered in grade_object::fetch_helper(...)

if (count($instances) > 1) {
    // we should not tolerate any errors here - problems might appear later
     print_error('morethanonerecordinfetch','debug');
}

If i delete the extra rows the next user is able to complete the course without error but all completions afterwards will being showing the error again and the extra rows are re-inserted.

I have not been able to track down where or why these additional rows are being inserted but is causing a big problem. I'll also mention that if the user refreshes the page after seeing the "Found more than one record in fetch() !" error the page is displayed correctly and they see the "Congratulations - end of lesson reached" page.

If anyone could shed any light onto why this might be happening or what can be done to fix it that would greatly appreciated.

Thanks

This is using Moodle version 3.2.3+ (Build: 20170601)

I have also included some screenshots.



Attachment duplicate_grade_items.png
Attachment grade_items.png
Attachment moodle_complete_lesson_error.png
Average of ratings: -