Problem in Quiz

Problem in Quiz

by Sam Black -
Number of replies: 25

Two of my students were taking an exam for me today (out of 60 that have taken this exam successfully) and ran into a problem.

One of them got the below message, the other one -- the only difference is that his question numbers mentioned are different.

Can not find wrapped question 3995,3996,3997,3994,3993:


Wrapped state missing

Any thoughts?

Average of ratings: -
In reply to Sam Black

Re: Problem in Quiz

by Sam Black -

Forgot to mention.  Running 1.8.3+ and have been since late last fall.

Any ideas what would cause this?  Can it be avoided/fixed?

Thanks again!

In reply to Sam Black

Re: Problem in Quiz

by Pierre Pichet -
This message indicates that you used random questions and you could have some problem if there is an insufficient number of questions to choose from.

Pierre

In reply to Pierre Pichet

Re: Problem in Quiz

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers
The message is from the random question type. However it is nothing to do with having an insufficient number of questions to choose from. To get that error, something much weirder must have happened. It is one of those messages you should never see under normal operation.
In reply to Tim Hunt

Re: Problem in Quiz

by Sam Black -

Well, I've been using Moodle for around three years now and have had 46 other students take this particular exam in addition to the two with problems.  I've never run across this particular issue before.  I'm hoping this is pretty isolated. as it's been almost two years and two "tenths" -point versions since a similar issue was reported here.

If it's an unusual problem, I'll likely be the one for it to happen to.  cool

Thanks for any suggestions.

In reply to Sam Black

Re: Problem in Quiz

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers
Well, really all you can do is try to make it happen again, and if you can, try to work out exactly what you did to make it happen. Unless we can find out what the cause is, it is very hard to do anything about it.
In reply to Tim Hunt

Re: Problem in Quiz

by Brent Sawatzky -
I seem to be encountering this error a lot on a newly setup server version 1.8.4

Courses were restored from individual backups.

Errors when previewing tests include:

Wrapped state missing.

This question has been deleted. Please contact your teacher.
(although the questions are infact present)


Encountered a PHP stack overflow.

I don't know exactly what is causing these errors, especially the variety in which they present themselves, all I can tell you is that I haven't seen them on two previous servers with the same courses running on them.

What seems to fix all these random errors however is going to the 'edit'
tab of each quiz individually and pressing 'save changes' (without actually making any changes). After doing that the tests display no errors when previewing.


In reply to Brent Sawatzky

Re: Problem in Quiz

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers
The last bit: "Encountered a PHP stack overflow" says (approximately) that the server ran out of memory while trying to process the request. That is probably the root cause of the other error messages. I don't really know why that should be happening, though.
In reply to Tim Hunt

Re: Problem in Quiz

by Chris Potter -
I've gotten this message twice now "Wrapped state missing" from the same course (I believe the same quiz also), but I've never seen it anywhere else, and I don't get the "questions have been deleted" part of the message.

My system setup:
Moodle 1.8
Windows 2003 x64
MySQL 5.0.41
PHP 5.2.2
Apache 2.2.4

Here's how the quiz is set up:

50 questions total worth 100 points
pulled randomly from 2 question banks (25/each)
Each question bank has 50 questions (100 total)

I have not tried to replicate this myself... but I presume it could be done if I tried with a student account. I'll see what I can do. It's also happening on the same machine (but the machine is identical to 100's of other computers on campus).

If I delete the current attempt and then have them restart the quiz, it doesn't occur a second time.

Is there anything I can do to help troubleshoot this? The instructor is very flexible, but I don't wish it to happen to a student who's instructor that isn't. :S

Thanks.
In reply to Chris Potter

Re: Problem in Quiz

by Chris Potter -
Just a thought... but what kind of questions are they? Are there any calculated ones? I seem to recall our professor using calculated questions on his exam.
In reply to Chris Potter

Re: Problem in Quiz

by Chris Potter -
I've been trying to narrow down this oddity, and here's what I've noticed:

-Both AIKEN and Examview imported question pools have done it when added to a quiz
-Questions that do this seem to partially break the "regrade" feature and the attempts are removed (visually, not from the DB) from view in the results (though it still shows the attempts are made).
-Happening in multiple courses
-Happening to multiple students
-Deleting the attempt usually corrects the error for that student (not ideal for larger exams... students aren't thrilled usually... :S).


My biggest concern is the regrading... it seems like only part of them have been fixed, and I'm a little concerned that not all of them will be fixed. I have not tried going to "edit" the quiz and then just clicking save to see if this resolves them. I will give this a try, but it'll make it extremely difficult to track, since it's never happened to me.

Can anyone provide a bit of a logic path for why this occurs? Even a general one would be awesome. I just don't get why this is occurring.
In reply to Chris Potter

Re: Problem in Quiz

by Chris Potter -
Seems like I'm talking to myself... smile This is good for everyone else, and bad for me. Anyway, I managed to find that in both cases that I received this message recently, there was an inconsistency with Moodle and the question_states table, relating to the random questions. Would anyone know why the attached picture might occur?? Notice entry 376815 has just one answer and no "random#####-" before it. That to me indicates (from what I've gathered on my own) that the question itself never got assigned to the proper answers, or only partially. Am I wrong? Would anyone disagree that something is wrong here?

question states issue?


Thanks for all the help you can provide!
In reply to Chris Potter

Re: Problem in Quiz

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers
Whether that is a problem depends on what question types question 58648 is. (If I remember rightly, the third column in this table is the question id.) If that question is a MC question, not a random one, then this is OK. If it is a random question, then yes, you have a problem.
In reply to Tim Hunt

Re: Problem in Quiz

by Chris Potter -
Tim,

Sorry to dredge this one up again, but I must have missed your reply in one of the Digests when you originally replied... Anyway, still experiencing this issue with update to 1.8.6+... Also, yes indeed the question "58648" was a random question.

I noticed in the code notes it says that this happens with the "old method" of storing questions from back prior to Moodle 1.5. We started on 1.5.3, but by the time we had rolled out anything, we were at 1.6 (on a completely fresh install) and didn't even use this particular question set.

I have some instructions as to how I correct it, but it's certainly not ideal, considering it's a direct access to the database, I don't feel all that comfortable editing it (for fear of further inconsistencies), and it can only be fixed after it's reported (meaning the students are stuck until I fix it). The most recent occurrence threw another twist: In the questions column in the question_states table, there were two questions with the same number and had different "random#####" parts of the answer field (One matches the question, the other was the correct one).

I really wish I had a way to perfectly replicate this for you, and I know it's extremely difficult to troubleshoot without it. Would a set of sample data help?

Thanks Tim, I know you're a busy guy and have a lot to do.
In reply to Chris Potter

Re: Problem in Quiz

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers
You are right that finding a reliable way to reproduce this would be the most helpful thing you could do.

And you don't need to wait for students to to report problems to you. A query like:

 
SELECT * FROM
mdl_question q JOIN
mdl_question_states qst ON qst.question = q.id
WHERE
q.type = 'random' AND
qst.answer NOT LIKE 'random%';


should find all the problem states for you.

Just editing the contents of the question_states.answer is probably relatively safe. Obviously you still want a full backup first, and you probably want to practice on a copy of your site, not the live system, first. However, changing stuff here can only affect the questions in the attempts that are already broken, and if you are doing sensible sorts of changes, then you are unlikely to make things worse -aren't you?
In reply to Tim Hunt

Re: Problem in Quiz

by Chris Potter -
All of what you're saying makes sense. The query above worked after changing the 'q.type' to 'q.qtype'. smile I've got 316 of them... sad Most look like they're from previous semesters attempts. I don't have that many instructors that use the "random" question type... but the one who's getting is the most active online instructor we have (naturally). I wouldn't think there's some sort of magic threshold, considering she's only got about 30 students and they're only allowed one attempt. Some don't have any problem, this last case ended up with two in one quiz. Is there any way that I might be able to systematically create this error? I suppose I could build a quiz with the same set up (actually, copying one of those quizzes would be best), and just take it with some sample accounts until it happens. It must be happening on quiz generation though. Maybe a check to see if they were generated properly before the student attempts it?

I need to investigate more... *sigh*... sad

Thanks for the help Tim.
In reply to Chris Potter

Re: Problem in Quiz

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers
Sorry about they typo in the DB query.

Don't worry too much about the apparent quantity, you can get a lot of question_states for just one student's quiz attempt, so the problem may not be as bad as that.

The sixty four thousand dollar question is: can we work out how to systematically create this error (reproduce it). If we can, it massively increases the chance of fixing it.
In reply to Tim Hunt

Re: Problem in Quiz

by Chris Potter -
Systematically? I suppose eventually with enough quiz attempts... but that doesn't really help either because that's not going to consistently reproduce the problem. I'm going to run some tests on a dev. server with mirrored code from the live server, add a bit of extra code for debugging and see if I can't get an idea of when it might happen. There's got to be something tripping it up, but on the surface it seems quite random...

-Multiple students
-Multiple tests
-Multiple classes
-Multiple question categories

Thanks again... I know it's not easy working with someone who can't figure out how to make it happen... lol
In reply to Chris Potter

Re: Problem in Quiz

by Chris Potter -
So, I haven't permanently given up on finding the source of the problem, but perhaps a way to correct it "as it happens" seemed to be a reasonable alternative until I can figure this out for sure. Using my steps to correct the issue when it happens, I jotted down this script. Any thoughts on something like what's below that runs when the error message occurs? It's not elegant and certainly isn't perfect, but maybe it would help (Note: not a PHP expert here)?

//Get the first value from the csv list of answers to use for query
$answerids = implode(',', $state->responses); //Convert to string
$answeridsarray = explode(',', $answerids); //Convert to array
$answerid = $answeridsarray[0]; //Just get one for the query
//Let's get the record we need so we can update it
$sql = "SELECT * FROM ".$CFG->prefix."question_answers WHERE id=".$answerid;
$quizanswer = get_record_sql($sql);
$questionid = $quizanswer->question;
$stringtoinsert = 'random'.$questionid.'-'.$answerids;
$state->responses = $stringtoinsert;
$recordtoupdate = clone($state);
$recordtoupdate->answer = $stringtoinsert;
if(!update_record('question_states',$recordtoupdate)) {
notify("Error correcting wrapped state issue...");
} else {
notify("Record corrected. Refresh the page to continue.");
}
In reply to Chris Potter

Re: Problem in Quiz

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers
I don't understand the implode followed by the explode in the first two lines.

And it is not obvious what your code is doing at first, but I think I get it now. That's quite clever - assuming I am right.

You are using the fact that the state should look like:

random[id of randomly selected question]-[answerid],[answerid],...

whereas all you have is

[answerid],[answerid],...

However, each answer belongs to only one question, so from the answerid, you can get the questionid you need.

I think the only problem you might have is that if the multiple-choice question has the 'shuffleanswers' option turned on, then the stored answer will look like - Oh! it is still a comma-separated list of answerids, so you are safe. There will just be a colon in the middle.

The remaining danger is that someone has done a random question that selected short-answer, or worse numberical questions. I would probably prefer to use preg_match to get an answerid out.

$matches = array();
if (preg_match('/^(\d+)(,\d+)*(:\d+(,\d+)*)?)$/', $state->responses[''], $matches) {
$answerid = $matches[1];
// ...
}

Hmm. Still no way to distinguish a numerical qestion with an integer response, and a MC question with a single answer, and no shuffling.
In reply to Tim Hunt

Re: Problem in Quiz

by Chris Potter -
Thanks for the feedback... It's much appreciated. I'll see what changes I can make to try to consider these factors. We don't currently have anyone who uses random short answer or numerical, but the fact that it could happen at some point means it should be considered of course. Hmm...
In reply to Tim Hunt

Re: Problem in Quiz

by Jet Batung Bakal -

Sir Tim,

About the random question. Is there a possibility that the system reacts or it can  an error if for example the teacher/prof create a quiz after that he/she random it and then erase those question's in the Question Bank? Reply Soon!

Thanks,

Julius Barrameda

In reply to Jet Batung Bakal

Re: Problem in Quiz

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers
Yes, teachers cans screw up like that. If they do, there is a little mesasge "Not enough questions in this category" or something in place of the random question.
In reply to Tim Hunt

Re: Problem in Quiz

by Jet Batung Bakal -

Ok then, but are those questions can be read or seen by the student? In my moodle Sir Tim after the professor do that ( create question/s from the question bank,random it and then erase those she/he created questions from the question bank) the student even I as admin can able to access on that activity and read those random questions but it cannot be edited. My question is Sir Tim after that observation the error occured such as: one student complaint that after she answer all those random questions the totalled percentage the she get is not tallied in the correct answers. I tried to regrade it but an error occured that says ( Can not find wrapped question ). Second problem, another student complaint that she cannot access on those random questions and it says ( can not find wrapped question   108071,108070,108069,108072:108070 wrapped state missing). Is there a connection with what the proffessor did to create his/her question? Help Pls to solve this Thanks a lot.

Ps:

Another question with regards to that. Is there also a connection with regards on how the student handle the system (moodle) that cause an error? 

Sincerely,

Julius Barrameda

In reply to Tim Hunt

Re: Problem in Quiz

by Jet Batung Bakal -
By the way Sir Tim, the questions that I'm mentioned about is not totally in the question bank of the course/subject but instead in the activity it self. And addition to that when I look the CATEGORY SECTION I saw those question and the professor make add sub category of one of the category. I doubted on this set up if this kind of questions that the professor did has the connection of this errors? This just an allegation. Please give a proper advise of this problem. This is in connection with my first topic.