Unexpected Event code found for question X in attempt X

Unexpected Event code found for question X in attempt X

by Dave Johnson -
Number of replies: 13

Hello!

Our district site has been using Moodle 2 since the Release Candidate with no major problems.  Last month however (while still using the RC) we came into an issue with quizzes.  Random students (different each time) would get an Unexpected Event code when starting the tests. Half of my students were able to take the quiz with no problems, the other half were not.  LUckily I plan for problems like this.

 

We chalked this up to running the release candidate.  Over the long Presidents Day weekend my tech guy upgraded Moodle.  We actually ended up having to completely overwrite everything because the upgrade didn't take.  We hoped that this would correct the problem (now using 2.0.2)

Gave my first US History test today on the new server and still had the same old problem.

We are running 2.0.2 on a Windows 2008 server.  ANyone else having this problem?  Anyone know if we're doing something wrong (Aside from using a Microsoft server...that's not helpful smile)

Average of ratings: -
In reply to Dave Johnson

Re: Unexpected Event code found for question X in attempt X

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've never seen that error before. Are you able to do some investigation?

This error comes from line 712 of mod/quiz/attemptlib.php

Try

SELECT DISTINCT event FROM mdl_question_states

The only values there should be 0, 2, 3, 6, 7, 8, 9.

If you have other values, please can you try to work out which quiz attempt they belong to by using the database query here: Development:Question database structure#Following_what_happens_when_questions_are_attempted, and what is going on.

Those even numbers can be turned into more meaningful constan names using the constants at the top of lib/questionlib.php.

 

As a temporary work-around to the problem, at around line 707 mod/quiz/attemptlib.php, just after the line that says

default:

add a line something like

return 'unknown';

so that it does not throw an exception in this situation. However, that just hides the real bug. It is worth investigating to find out what is really going on.

 

P.S. I wish you had reported the problem when you first encountered it. I'm surprised no one else has hit it yet.

In reply to Tim Hunt

Re: Unexpected Event code found for question X in attempt X

by Dave Johnson -

Okay...you're dealing with a newbie here with limited coding experience.  Unless you count qbasic.

I need to get on to the actual Moodle server for this, correct?  I have access, but not over the weekend, so if so I will have to try this on Monday when I return.

Since I'm currently the only teacher in my distric tusing Moodle, I figured this was the result of it being the Release Candidate.  I didn't report it because I had changed some things at the admin level and I thought...maybe?  I didn't change anything this time though.

 

 

In reply to Dave Johnson

Re: Unexpected Event code found for question X in attempt X

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, I tend to forget that there are people in the world who don't speak fluent geek. Or rather, I know that if I explain, then some people will be able to use the information, and if other people cannot, and just ignore it, then no harm done.

 

If you want to be able to investigate in the database, phpMyAdmin can be a convenient way to do that, providing you are careful not to change anything unintentionally.

 

My P.S. was not a criticism. Just futile wishing for the benefit of hindsight.

In reply to Tim Hunt

Re: Unexpected Event code found for question X in attempt X

by Brigitte Baquero -

I am having the same problem.

 

Código de evento inesperado encontrado en la pregunta 568 en el intento 8103.

Más información sobre este error

Stack trace:
  • line 723 of /mod/quiz/attemptlib.php: moodle_quiz_exception thrown
  • line 1144 of /mod/quiz/attemptlib.php: call to quiz_attempt->get_question_status()
  • line 1137 of /mod/quiz/attemptlib.php: call to quiz_nav_panel_base->get_question_button()
  • line 1200 of /mod/quiz/attemptlib.php: call to quiz_nav_panel_base->get_question_buttons()
  • line 894 of /mod/quiz/attemptlib.php: call to quiz_nav_panel_base->get_contents()
  • line 98 of /mod/quiz/attempt.php: call to quiz_attempt->get_navigation_panel()
Output buffer: <br /> <b>Notice</b>: Undefined index: 568 in <b>/home/tigo/public_html/moodle/mod/quiz/attemptlib.php</b> on line <b>697</b><br /> <br /> <b>Notice</b>: Trying to get property of non-object in <b>/home/tigo/public_html/moodle/mod/quiz/attemptlib.php</b> on line <b>698</b><br /> <br /> <b>Notice</b>: Trying to get property of non-object in <b>/home/tigo/public_html/moodle/mod/quiz/attemptlib.php</b> on line <b>720</b><br />
In reply to Tim Hunt

Re: Unexpected Event code found for question X in attempt X

by Brigitte Baquero -

I am having the same problem.

 

Código de evento inesperado encontrado en la pregunta 568 en el intento 8103.

Más información sobre este error

Stack trace:
  • line 723 of /mod/quiz/attemptlib.php: moodle_quiz_exception thrown
  • line 1144 of /mod/quiz/attemptlib.php: call to quiz_attempt->get_question_status()
  • line 1137 of /mod/quiz/attemptlib.php: call to quiz_nav_panel_base->get_question_button()
  • line 1200 of /mod/quiz/attemptlib.php: call to quiz_nav_panel_base->get_question_buttons()
  • line 894 of /mod/quiz/attemptlib.php: call to quiz_nav_panel_base->get_contents()
  • line 98 of /mod/quiz/attempt.php: call to quiz_attempt->get_navigation_panel()
Output buffer: <br /> <b>Notice</b>: Undefined index: 568 in <b>/home/tigo/public_html/moodle/mod/quiz/attemptlib.php</b> on line <b>697</b><br /> <br /> <b>Notice</b>: Trying to get property of non-object in <b>/home/tigo/public_html/moodle/mod/quiz/attemptlib.php</b> on line <b>698</b><br /> <br /> <b>Notice</b>: Trying to get property of non-object in <b>/home/tigo/public_html/moodle/mod/quiz/attemptlib.php</b> on line <b>720</b><br />
In reply to Brigitte Baquero

Re: Unexpected Event code found for question X in attempt X

by Joshua Saxon -

Me too.

I can't preview the quiz as an Admin, but I can take it as a Student.

It says: Unexpected event code found for question 119 in attempt 158.

In reply to Tim Hunt

Re: Unexpected Event code found for question X in attempt X

by Guido Hornig -
Picture of Plugin developers

Hi Tim

Unexpected event code found for question 19 in attempt 21.

I get this error for the second attempt of a quiz with 13 questions after I deleted all attemps from the quiz with Reset Course .

I checked  "SELECT DISTINCT event FROM mdl_question_states" and got 0,2,3,6,7,8. No others.

I upgraded to  Moodle 2.0.3+ (Build: 20110623) from 20110525 with and nothing changed.

I will try to set up a new quiz and will report this later.

 

After first try for second attemp, I get this

Notice: Undefined property: stdClass::$last_graded in /is/htdocs...www/moodle/lib/questionlib.php on line 1700

Fatal error: __clone method called on non-object in /is/htdocs...www/moodle/lib/questionlib.php on line 1700

And after triing again:

Notice: Undefined index: 19 in /is/htdocs/.../www/moodle/mod/quiz/attemptlib.php on line 697

Notice: Trying to get property of non-object in /is/htdocs/.../www/moodle/mod/quiz/attemptlib.php on line 698

Notice: Trying to get property of non-object in /is/htdocs/.../www/moodle/mod/quiz/attemptlib.php on line 720

Notice: Undefined property: stdClass::$last_graded in /is/htdocs...www/moodle/lib/questionlib.php on line 1700

Fatal error: __clone method called on non-object in /is/htdocs...www/moodle/lib/questionlib.php on line 1700

 

I will try to set up a new quiz and will report this later.

In reply to Guido Hornig

Re: Unexpected Event code found for question X in attempt X

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 problem seems to be that an expected question_states row is missing from the database (rather than just having a wrong event value). I have no idea how that could have come about.

In reply to Tim Hunt

Workaround does not workaround...

by mart van der niet -

Hi,

I've got the same problem:


Notice: Undefined index: 876 in /home/users/prinqftp/examen.prince2leren.nu/mod/quiz/attemptlib.php on line 412

Notice: Trying to get property of non-object in /home/users/prinqftp/examen.prince2leren.nu/mod/quiz/attemptlib.php on line 412

Notice: Undefined property: stdClass::$id in /home/users/prinqftp/examen.prince2leren.nu/mod/quiz/attemptlib.php on line 1133

Notice: Undefined index: in /home/users/prinqftp/examen.prince2leren.nu/mod/quiz/attemptlib.php on line 686

Notice: Trying to get property of non-object in /home/users/prinqftp/examen.prince2leren.nu/mod/quiz/attemptlib.php on line 687

Notice: Trying to get property of non-object in /home/users/prinqftp/examen.prince2leren.nu/mod/quiz/attemptlib.php on line 709

 

Debug info: Column 'questionid' cannot be null
INSERT INTO mdl_question_sessions (attemptid,questionid,newest,newgraded,sumpenalty,manualcomment,manualcommentformat,flagged) VALUES(?,?,?,?,?,?,?,?)
[array (
0 => '196',
1 => NULL,
2 => 18070,
3 => 18070,
4 => '0.0000000',
5 => '',
6 => '1',
7 => 0,
)]
Stack trace:
  • line 394 of /lib/dml/moodle_database.php: dml_write_exception thrown
  • line 874 of /lib/dml/mysqli_native_moodle_database.php: call to moodle_database->query_end()
  • line 916 of /lib/dml/mysqli_native_moodle_database.php: call to mysqli_native_moodle_database->insert_record_raw()
  • line 1353 of /lib/questionlib.php: call to mysqli_native_moodle_database->insert_record()
  • line 166 of /mod/quiz/processattempt.php: call to save_question_session()

 

I checked the DB:

 

SELECT DISTINCT event
FROM mdl_question_states
LIMIT 0 , 30

Results are : 0, 6, 3, 2

 

Your propose workaround:

I changed the code to:

public function get_question_status($questionid) {
$state = $this->states[$questionid];
switch ($state->event) {
case QUESTION_EVENTOPEN:
return 'open';

case QUESTION_EVENTSAVE:
case QUESTION_EVENTGRADE:
case QUESTION_EVENTSUBMIT:
return 'answered';

case QUESTION_EVENTCLOSEANDGRADE:
case QUESTION_EVENTCLOSE:
case QUESTION_EVENTMANUALGRADE:
$options = $this->get_render_options($questionid);
if ($options->scores && $this->questions[$questionid]->maxgrade > 0) {
return question_get_feedback_class($state->last_graded->raw_grade /
$this->questions[$questionid]->maxgrade);
} else {
return 'closed';
}

default:
return 'unknown';// WORKAROUND nav Mustafa probleem MN 30-06-2011
$a = new stdClass;
$a->event = $state->event;
$a->questionid = $questionid;
$a->attemptid = $this->attempt->id;
throw new moodle_quiz_exception($this, 'errorunexpectedevent', $a);
}
}

 

I flushed the buffers, logged in through another account, but the problem still is there!

 

Mart van der Niet


In reply to mart van der niet

Re: Workaround does not workaround...

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

That is actually a different problem - it starts with the first error. It seems like this quiz attempt is referring to questionid 876, but that question does not exist in the question bank. I guess someone deleted it, which Moodle should prevent if the question is in use by a quiz.

All the other errors follow on from that initial problem.

In reply to Tim Hunt

Re: Workaround does not workaround...

by mart van der niet -

From the debug messages I would say that questionid 876 is missing, but:

- in mdl_quiz.questions id:876 is not in the list of questions for this quiz

- when editing the quiz it shows the correct number of questions (75) for this quiz, with text for all of the questions...

 

MN

In reply to Tim Hunt

Re: Unexpected Event code found for question X in attempt X

by Guido Hornig -
Picture of Plugin developers

I tried a Quiz that allows only 3 attempts / higest grade and this shows better behavior -no error until now.

It also works fine for new quizes wit hunlimited attempts.

 

One guess:  The upgrade xml was not 100% ok in one of the 2.0.x Upgrades?

In reply to Dave Johnson

Re: Unexpected Event code found for question X in attempt X

by Raúl Garoña -

Hi,

We have Moodle 2.0.10 on ubuntu 10.04 with php 5.3.

Our problem is that values in the table question_sessions of some attempts were not being stored in the database. You can check it with this query:

SELECT * FROM [prefix]question_sessions n where attemptid = (yout attempt id)

I solved this issue with this ugly hack in the file mod/quiz/attemptlib.php

public function get_question_status($questionid) {
        //************START PATCH **************
        if (!isset($this->states[$questionid])){
              $this->states[$questionid]->event = 0;
              $this->states[$questionid]->flagged = 0;
        }
        //************END PATCH ***************
        $state = $this->states[$questionid];
        switch ($state->event) {
            case QUESTION_EVENTOPEN:
                return 'open';

            case QUESTION_EVENTSAVE:
            case QUESTION_EVENTGRADE:
            case QUESTION_EVENTSUBMIT:
                return 'answered';

         ....