Questions won't add to quiz

Questions won't add to quiz

Donna Hrynkiw -
回帖数:7
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
回复Donna Hrynkiw

Re: Questions won't add to quiz

Bill Click -
We experienced this same exact problem and the only work-around for us was to recreate the quiz.  same as you did.  Would like to hear how we corruted our data to cause the problem, but we must have.
回复Donna Hrynkiw

Re: Questions won't add to quiz

Tim Hunt -
Core developers的头像 Documentation writers的头像 Particularly helpful Moodlers的头像 Peer reviewers的头像 Plugin developers的头像
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:
  1. Get the quiz id (that is the number at the any URL that looks like ...q=123 (not ...id=456).
  2. Extract the contents of that row from the quiz database table (SELECT * FROM mdl_quiz WHERE id=123)
  3. Extract the contents of the quiz_question_instances table for that quiz (SELECT * FROM mdl_quiz_question_instances WHERE quiz =123)
Get all that into a text file or spreadsheet, and attach it to the tracker issue. With luck that might provide enough clues to diagnose the problem, but there is no guarantee.


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.
回复Tim Hunt

Re: Questions won't add to quiz

Larry Elchuck -
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)
  • 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()
hope this helps

回复Larry Elchuck

Re: Questions won't add to quiz

Olli Savolainen -
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.


回复Olli Savolainen

Re: Questions won't add to quiz

Tim Hunt -
Core developers的头像 Documentation writers的头像 Particularly helpful Moodlers的头像 Peer reviewers的头像 Plugin developers的头像
Yes, the field quiz.questions should be a comma-separated list of question ids, with 0s for page breaks, including a 0 at the end.

have a look in the mdl_quiz table to see if that is the case.
回复Tim Hunt

Svar: Re: Questions won't add to quiz

Marcus Rejås -
Hello, we too see this problem in the latest version of 1.9.

Lots of fields in mdl_quiz.questions with consecutive commas. Is there a solution to this other than to clean them manually?