Details
-
Bug
-
Status: Closed
-
Minor
-
Resolution: Fixed
-
3.5.2, 3.6
-
MOODLE_35_STABLE, MOODLE_36_STABLE
-
MOODLE_35_STABLE
-
MDL-63798_assign_restore_groups -
Description
Steps to reproduce:
- Create a course
- Create a group
- Enrol 2 users in the course, 1 in the group, 1 not in the group
- Create an assignment, with group submission on, but do not require users to be a member of a group to submit
- Log in as each of the users and submit something for the assignment
- Log back in as admin and delete the group
- Backup + restore the course
Expected result:
- Backup restores successfully
Actual result:
- Error: "ERROR: duplicate key value violates unique constraint "mdl_assisubm_assusegroatt_uix"
DETAIL: Key (assignment, userid, groupid, attemptnumber)=(2, 0, 0, 0) already exists.
INSERT INTO mdl_assign_submission (userid,timecreated,timemodified,status,groupid,attemptnumber,latest,assignment) VALUES($1,$2,$3,$4,$5,$6,$7,$8) RETURNING id
[array (
'userid' => '0',
'timecreated' => '1540804290',
'timemodified' => '1540804297',
'status' => 'submitted',
'groupid' => 0,
'attemptnumber' => '0',
'latest' => 0,
'assignment' => 2,
)]
Error code: dmlwriteexception"
Reason: during restore, mod_assign maps any groupids it can't find onto 0 (no group), but there is already a no group submission in the same backup, so this causes the unique key violation.
Suggested fix: skip restore of any assign submissions where the groupid is set but the group does not exist in the backup (as those submissions cannot be viewed anyway).