Missing answers on graded completed quiz

Missing answers on graded completed quiz

by Tim Beachy -
Number of replies: 5

On Moodle 3.2

We've had an alarming situation arise recently.  On fully completed, graded quiz attempts, the students' answers are missing.  Not only is this a problem in and of itself, but it's also causing issues for navigation through the courses because of activity restrictions we've set up.  Even though they have a completed quiz attempt, it won't allow them to advance to the next activity until the quiz is completed.

After initial investigation, it would appear that this has happened for quizzes going back several years, which I find hard to believe...it would have come up before now.  So my working theory is that there is corruption in the db somewhere that is causing this, but so far have not found it.

I haven't found a common thread between which attempts are like this, and which ones are fine.  We've also found that submitting  a new attempt will grade properly and allow the student to move on.

When attempting to access an attempt with missing answers we get the error "Unexpected Question state".

Here's the full debug output:

Coding error detected, it must be fixed by a programmer: Unexpected question state.
More information about this error
Debug info: 
Error code: codingerror
Stack trace:
  • line 297 of /question/engine/states.php: coding_exception thrown
  • line 617 of /question/engine/questionattempt.php: call to question_state_notstarted->get_state_class()
  • line 2435 of /mod/quiz/attemptlib.php: call to question_attempt->get_state_class()
  • line 333 of /mod/quiz/renderer.php: call to quiz_nav_panel_base->get_question_buttons()
  • line 1659 of /mod/quiz/attemptlib.php: call to mod_quiz_renderer->navigation_panel()
  • line 255 of /mod/quiz/review.php: call to quiz_attempt->get_navigation_panel()
Any help with either a good query to investigate this further, or an indication of where to look is much appreciated!  I can't seem to find anyone who has experienced this before...



Attachment debug-output.JPG
Attachment missing answers.JPG
Average of ratings: -
In reply to Tim Beachy

Re: Missing answers on graded completed 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

They error is just a symptom of the fact that the data is missing. That is the root cause. And, since this data shoudl never go missing, the fact that this in this situation you get this error is not really something that needs fixing.

Most databases have a command to scan for corruption, but it seems unlikely that it would delete some rows but not others.

The most likely cause is human error. Who has access to your database? Might they have done some ill-thought-out housekeeping?

This documentation: https://docs.moodle.org/dev/Overview_of_the_Moodle_question_engine#Detailed_data_about_an_attempt may help you make sense of what is in the database.

In reply to Tim Hunt

Re: Missing answers on graded completed quiz

by Tim Beachy -

Thank your for the query Tim -- using it I was able to confirm that what you say is true, and does correspond to a time when some db actions were going on.  

We have backups, but now I'm wondering how in the world we can restore the missing data without messing up new data that has been entered since then?


In reply to Tim Beachy

Re: Missing answers on graded completed 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 would start by comparing the data in the backup with the data in the database - for the tables related to quizzes and questions.

Obviously, the database will contain new data, with timestamps newer than when the backup was made, but that is not relevant.

You need to look at the data that is in the backup that has been removed from the database. If you can identify that, you might be able to re-insert it and fix things.

In reply to Tim Hunt

Re: Missing answers on graded completed quiz

by Tim Beachy -

Thank you Tim, all good advice.

I compared the two and found that all the missing data was confined to question_attempt_steps.  I had been worried the autonumbering of the ID field, and how to bring them together if say, the current db had started renumbering at the spot where missing data was supposed to go.   But, as it turned out, there was simply a 2 million record hole in the table, and once I exported that series from backup and reimported into the live database, everything seems back to normal.

Thanks again!

In reply to Tim Beachy

Re: Missing answers on graded completed 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 done for piecing that together.