Affects Version/s: 2.5.1, 2.5.2, 2.5.5, 2.6.3, 2.7
- in a course of 1000 students,
- create an assignment with blind marking and offline grading worksheet enabled
- Login as a teacher
- Now download a grading worksheet
- Check the database for records in mdl_assign_user_mapping with assignid = 0 (there should be none)
Affected Branches:MOODLE_25_STABLE, MOODLE_26_STABLE, MOODLE_27_STABLE
Fixed Branches:MOODLE_25_STABLE, MOODLE_26_STABLE, MOODLE_27_STABLE
Pull from Repository:
Pull Master Branch:
Pull Master Diff URL:
Our mdl_assign_user_mapping table has millions of records
with id, userid and assignment set to 0. I explain the location of
the bug, and easy fix, and document the use case on how this happens to us.
the mdl_assign_user_mapping table holds 3 fields, (id, assignment, user). the id gets used for uploading/mapping feedback. In mod/assign/locallib.php around 5945 function allocate_unique_ids, there is an insert statement which doesn't include the assignment id.
In that file, there are 2 locations of an insert_record for that table. the other function get_uniqueid_for_user_static, does it correctly.
5976 $record = new stdClass();
5977 $record->assignment = $assignid;
5978 $record->userid = $userid;
5980 return $DB->insert_record('assign_user_mapping', $record);
to fix in the first function,
Here is the use case and scenario to re-create -
we have a class of 1000 students,
we are using the assignment module as a dropbox for files from the instructor to the student.
create an assignment with no submission items selection, but grading worksheet and feedback files by the instructor.
Now download a grading sheet. (this triggers the bug that creates 1000,s of incorrect entries in that table).
Its kind of crazy what it does, for 1000 students in the course, it adds 1 valid record (id, assignment, userid), then 999 (id, 0, userid), then it does
another record correctly, then 998 with (id,0, userid)
Easy fix, if one clicks the grade in the assignment, that triggers the other function to set the values properly. but in our scenario it exploits the bug. For us to fix, we'll be deleting all entries where assignment=0 then optimize the 3,000,0000 + record table.