-
Bug
-
Resolution: Unresolved
-
Minor
-
None
-
4.5.4, 4.5.5, 5.0, 5.1, 4.5.6
On Friday after an error when restoring a course we found out we have some multianswer questions with an insane amount of subquestions.
SELECT parent, COUNT(*) as howmany |
FROM {question} |
WHERE parent > 0 |
GROUP BY parent |
HAVING howmany > 1 |
returned lines with counts above 10000, peaking with 41990 !!!
Investigating where this comes from we were able to indentify an error, which is still present in the current 5.1dev (Build: 20250605):
Steps to reproduce
- In an empty vanilla Moodle (using 5.1dev (Build: 20250605) but already present in 4.5)
- create an multianswer (embedded - cloze) question:
<p>Complete the sentences with the correct European capital city.</p> |
<p>The capital of France is {1:MULTICHOICE:London~Madrid~=Paris~Rome}.</p> |
And save.
- Confirmt that there are now two elements in the table question, question_versions, question_bank_entries. One row in question_multianswer. One row in qtype_multichoice_options.
- Edit the question changing MULTICHOICE to SHORTANSWER and save.
- Confirm that there are now four rows in the table question and question_versions, still two rows in the table question_bank_entries, two rows in question_multianswer, one row in qtype_shortanswer_options and - surprisingly - no row anymore in the table qtype_multichoice_options.
- Create a quiz activity and add this question to the quiz.
- Duplicate the quiz.
- Confirm that contrary to what expected, a new record was created in each of the tables question, question_versions, question_bank_entries.
- Duplicate the quiz activity a second time
- Confirm that this time two new records were created in each of the tables question, question_versions, question_bank_entries.
From now on, each time the quiz activity is duplicated, the number of new records created in these three tables will carry on growing exponentially.
Analysis
With the Xdebug we traced down the creation of the new question to line 700 of backup/utils/dbops/restore_dbops.class.php:
$matchqid = $questioncache[$question->questionhash]; |
For the multichoice subquestion from v1 of the question the hash does not match and this triggers the creation of a new question.
I am not sure yet why and if this is a regression caused by MDL-83541, could it be related to the fact that the entry in qtype_multichoice_options is removed when editing the question and changing its type, although the questions still exists as v1?