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

    Details

    • Testing Instructions:
      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
    • Affected Branches:
      MOODLE_24_STABLE, MOODLE_26_STABLE, MOODLE_27_STABLE, MOODLE_28_STABLE
    • Fixed Branches:
      MOODLE_27_STABLE, MOODLE_28_STABLE
    • Pull from Repository:
    • Pull Master Branch:
      MDL-46651-master-restore-course-completion-duplicate-key

      Description

      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

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              joshjohnston Josh Johnston
              Reporter:
              joshjohnston Josh Johnston
              Peer reviewer:
              John Okely John Okely
              Integrator:
              Dan Poltawski Dan Poltawski
              Tester:
              Marina Glancy Marina Glancy
              Participants:
              Component watchers:
              Adrian Greeve, Jake Dallimore, Mathew May, Mihail Geshoski, Peter Dias, Sujith Haridasan, Amaia Anabitarte, Carlos Escobedo, Ferran Recio, Ilya Tregubov, Sara Arjona (@sarjona)
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved:
                Fix Release Date:
                12/Jan/15