I have a mystery; my little grey cells are thrashing and need help.
Problem: Questions refuse to be added to quiz.
Symptoms:
- Quiz is empty
- While editing the quiz, clicking on the << to add a question causes the page to refresh, but the question does not appear in the quiz (it's still empty).
- No errors on the page
- No errors in php.log
- Questions are at an appropriate category level (Course, FWIW)
- Out of 8 quizzes in the course, accessing the same questions, two work fine and six are being uncooperative
- New quizzes, with identical settings to uncooperative quizzes, work fine
- Nobody else has reported this problem, it's restricted to this course
- A backup of the course restored to an entirely separate instance of Moodle has exactly the same problem.
Our work-around is to re-create new versions of the uncooperative quizzes, but we'd really like to know why the originals didn't work in the first place. The absence of errors feels to me like a configuration issue than an actual bug or bad data problem.
The teacher swears that all the quizzes were restored from the backup. So why do two work and the others not?
We're currently running Moodle v1.9.4+
The course backup was likely created under v1.9.3 or possibly slightly earlier. (Certainly after v1.9.0)
Tips, suggestions, and "We had a similar problem once..." comments gratefully accepted.
Donna Hrynkiw
Kwantlen Polytechnic
This is definitely a bug - this sort of thing should not happen.
However, it is the sort of bug that is very hard to do anything about because it is intermittent. Obviously bugs are much easier to fix if I can reproduce them on my own computer, because then I can poke around and find out what is happening.
Do we have a bug for this problem filed at tracker.moodle.org? We should certainly do that.
And, if this does happen again, what information might help me fix it? .... (thinks)
I think the following:
The only other option is, once you have a quiz that is failing, go into the code and start adding debugging statements (print_object($variable)) in the code that is meant to add a question, to try to work out what is going on.
However, it is the sort of bug that is very hard to do anything about because it is intermittent. Obviously bugs are much easier to fix if I can reproduce them on my own computer, because then I can poke around and find out what is happening.
Do we have a bug for this problem filed at tracker.moodle.org? We should certainly do that.
And, if this does happen again, what information might help me fix it? .... (thinks)
I think the following:
- Get the quiz id (that is the number at the any URL that looks like ...q=123 (not ...id=456).
- Extract the contents of that row from the quiz database table (SELECT * FROM mdl_quiz WHERE id=123)
- Extract the contents of the quiz_question_instances table for that quiz (SELECT * FROM mdl_quiz_question_instances WHERE quiz =123)
The only other option is, once you have a quiz that is failing, go into the code and start adding debugging statements (print_object($variable)) in the code that is meant to add a question, to try to work out what is going on.
Here's what I get at develop debugging level Tim
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ',,,,,,,586,587,633,624,703)' at line 3
SELECT question,grade,id FROM mdl_quiz_question_instances WHERE quiz = '42'AND question IN (,,,,,,,,586,587,633,624,703)
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ',,,,,,,586,587,633,624,703)' at line 3
SELECT question,grade,id FROM mdl_quiz_question_instances WHERE quiz = '42'AND question IN (,,,,,,,,586,587,633,624,703)
- line 686 of lib/dmllib.php: call to debugging()
- line 966 of lib/dmllib.php: call to get_recordset_sql()
- line 281 of mod/quiz/locallib.php: call to get_records_sql()
- line 127 of mod/quiz/edit.php: call to quiz_get_all_question_grades()
Which Moodle version are you using?
The quiz is not empty, but it seems the quiz layout is broken (,,,,,,,586,587,633,624,703). It is supposed to be numbers separated with commas, so the code in quiz that adds/removes/etc. questions in quiz must have screwed it up. There should never be consecutive commas, so the quiz editor is confused by this and shows nothing. Quiz should definitely give an error message when the quiz layout is broken, but I guess it doesn't. Why didn't I come to think of this last autumn when we were fighting with this issue for Moodle 2.0?
If you wish, you might want to edit the database at your own risk. The place to look for this is the 'mdl_quiz' table (assuming your db prefix is mdl_). Each quiz has a record in the table, and the layout (which questions are in a given quiz) is defined by the 'questions' field. If you manage to clean up the extra commas from this field, it should work again.
The proper format (Tim please correct me if I'm wrong), I think, is something like 1,2,3,4,5,6,0 - there is an empty page in the end. Zeros signify page breaks - in Moodle 2.0 two consecutive zeros (empty pages) are allowed, in Moodle 1.9 and lower not. There should always be a zero at the end.
The quiz is not empty, but it seems the quiz layout is broken (,,,,,,,586,587,633,624,703). It is supposed to be numbers separated with commas, so the code in quiz that adds/removes/etc. questions in quiz must have screwed it up. There should never be consecutive commas, so the quiz editor is confused by this and shows nothing. Quiz should definitely give an error message when the quiz layout is broken, but I guess it doesn't. Why didn't I come to think of this last autumn when we were fighting with this issue for Moodle 2.0?
If you wish, you might want to edit the database at your own risk. The place to look for this is the 'mdl_quiz' table (assuming your db prefix is mdl_). Each quiz has a record in the table, and the layout (which questions are in a given quiz) is defined by the 'questions' field. If you manage to clean up the extra commas from this field, it should work again.
The proper format (Tim please correct me if I'm wrong), I think, is something like 1,2,3,4,5,6,0 - there is an empty page in the end. Zeros signify page breaks - in Moodle 2.0 two consecutive zeros (empty pages) are allowed, in Moodle 1.9 and lower not. There should always be a zero at the end.