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

Found more than one entry for course completion

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: Minor Minor
    • None
    • 3.9.17, 4.0.4, 4.1.1
    • Course completion
    • MOODLE_39_STABLE, MOODLE_400_STABLE, MOODLE_401_STABLE

      We're getting the following error in a system with 150 000 users when trying to access the course completion:

       

      Debug-Info: 
      Error code: morethanonerecordinfetch 
      Stack trace: 
          line 498 of /lib/setuplib.php: moodle_exception thrown
          line 191 of /completion/data_object.php: call to print_error()
          line 75 of /completion/completion_aggregation.php: call to data_object::fetch_helper()
          line 121 of /completion/data_object.php: call to completion_aggregation::fetch()
          line 480 of /lib/completionlib.php: call to data_object->__construct()
          line 77 of /course/completion_form.php: call to completion_info->get_aggregation_method()
          line 214 of /lib/formslib.php: call to course_completion_form->definition()
          line 80 of /course/completion.php: call to moodleform->__construct() 

      Using the following query we figured out that there're multiple entries in mdl_course_completion_aggr and mdl_course_completion_criteria :

       

      SELECT COUNT(cc.id) AS anz, cc.* from mdl_course_completion_aggr_methd as cc GROUP BY cc.course, cc.criteriatype HAVING anz > 1 

      First we were a bit confused how this could happened, but finally, we figured out that in a very very rare scenario (multiple users are editing the same course at the same time and saving it while another user is currently editing it), this causes the issue.

       

      To reproduce the issue we created a very minimalistic script:

       

      <?php
       
      define('CLI_SCRIPT', 1);
      require_once('config.php');
       
      global $CFG;
      global $DB;
       
      require_once($CFG->dirroot.'/course/lib.php');
      require_once($CFG->libdir.'/completionlib.php');
       
      $course = $DB->get_record('course', array('id' => 10));
       
      $step = 0;
       
      while(true) {
          $completion = new completion_info($course);
          $completion->get_aggregation_method();
          $completion->clear_criteria();
       
          $aggdata = array(
              'course' => $course->id,
              'criteriatype' => null
          );
       
          $aggregation = new completion_aggregation($aggdata);
          $aggregation->setMethod(1);
          $aggregation->save();
       
          if($step % 1000 === 0) {
              mtrace(sprintf("%s done", $step));
          }
       
          $step++;
      } 

      When running this script in parallel (same machine), we can finally reproduce the issue after 1000 or 5000 steps.

       

       

            Unassigned Unassigned
            mstimvol Tim Volckmann
            Votes:
            4 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated:

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