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

Restore fails with "Error writing to database Duplicate entry for key 'mdl_courcomp_usecou_uix'"

XMLWordPrintable

    • MOODLE_24_STABLE, MOODLE_26_STABLE, MOODLE_27_STABLE, MOODLE_28_STABLE
    • MOODLE_27_STABLE, MOODLE_28_STABLE
    • MDL-46651-master-restore-course-completion-duplicate-key
    • Hide
      1. Enable completion tracking on the site (Home ► Site administration ► Advanced features) and the course (Home ► My courses ► Miscellaneous ► Course ► Edit settings)
      2. Create an assignment (you can have completion set to "Students can manually mark the activity as completed")
      3. Set up course completion to depend on the completion of assignment
      4. Login as an enrolled user, and mark that assignment as complete
      5. Run cron (possibly twice), ensure that course is marked as completed for this student
      6. Create a backup of the course with user course completion data
      7. Restore it in the same course
      8. While it is restoring, run php admin/cli/cron.php to force a cron run.
      9. Make sure there are no errors
      10. Check course completion report for the restored course and make sure that courses are marked as completed when needed and the completed time is the same as it was in original course and not the time of restore
      Show
      Enable completion tracking on the site (Home ► Site administration ► Advanced features) and the course (Home ► My courses ► Miscellaneous ► Course ► Edit settings) Create an assignment (you can have completion set to "Students can manually mark the activity as completed") Set up course completion to depend on the completion of assignment Login as an enrolled user, and mark that assignment as complete Run cron (possibly twice), ensure that course is marked as completed for this student Create a backup of the course with user course completion data Restore it in the same course While it is restoring, run php admin/cli/cron.php to force a cron run. Make sure there are no errors Check course completion report for the restored course and make sure that courses are marked as completed when needed and the completed time is the same as it was in original course and not the time of restore

      Course restore fails when restoring a large-ish course containing user completion data. I have a large course backup (18mb) that takes a few minutes to restore. If I restore it with user data then the restore fails with the error in the screen shot attached.

      I am assuming this is because cron completion calculations cause a race condition between the time the existing record is queried and the insert happens here:

      https://github.com/moodle/moodle/blob/master/backup/moodle2/restore_stepslib.php#L3312-L3327

      This seems to be similar to MDL-30466

            joshjohnston Josh Johnston
            joshjohnston Josh Johnston
            John Okely John Okely
            Dan Poltawski Dan Poltawski
            Marina Glancy Marina Glancy
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved:

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