-
Bug
-
Resolution: Fixed
-
Minor
-
3.7.5, 3.8, 3.9
-
MOODLE_37_STABLE, MOODLE_38_STABLE, MOODLE_39_STABLE
-
MOODLE_37_STABLE, MOODLE_38_STABLE
-
master_
MDL-67540 -
We noticed this bug as our client is setup with some database read-only slaves, but I believe the same issue could occur if two users happened to be trying to do this at the same time.
The users were attempting to add multiple quiz questions in one go (through the web-interface and through an external 'Respondus' tool). The first question was always added, but then they were met with a database error, saying the was already a unique key for that quiz id and slot id.
The issue boils down to the fact that in the database query to check the existing slots on the quiz, happens before the database transaction begins.
$slots = $DB->get_records('quiz_slots', array('quizid' => $quiz->id), 'slot', 'questionid, slot, page, id'); |
|
if (array_key_exists($questionid, $slots)) { |
return false; |
}
|
|
$trans = $DB->start_delegated_transaction();
|
To fix this, the transaction should simply be moved above the get_records call.
I'm attaching a .diff file. Let me know if you want me to actually create a github branch for it.