"Can't find data record in database" when attempting to preview Quiz

"Can't find data record in database" when attempting to preview Quiz

by Michael Woods -
Number of replies: 4
Picture of Core developers
We've recently upgraded from 4.0 to 4.3 and a number of staff are saying that quizzes which were working before the upgrade are now throwing an error.

"Can't find data record in database"

The full error stack on the server is as follows:

Default exception handler: Can't find data record in database. Debug: SELECT q.id, qc.id as category, q.parent, q.name, q.questiontext, q.questiontextformat,\n                       q.generalfeedback, q.generalfeedbackformat, q.defaultmark, q.penalty, q.qtype,\n                       q.length, q.stamp, q.timecreated, q.timemodified,\n                       q.createdby, q.modifiedby, qbe.idnumber,\n                       qc.contextid,\n                       qv.status,\n                       qv.id as versionid,\n                       qv.version,\n                       qv.questionbankentryid\n                  FROM {question} q\n                  JOIN {question_versions} qv ON qv.questionid = q.id\n                  JOIN {question_bank_entries} qbe ON qbe.id = qv.questionbankentryid\n                  JOIN {question_categories} qc ON qc.id = qbe.questioncategoryid\n                 WHERE q.id = :id\n[array (\n  'id' => '1088783',\n)]\nError code: invalidrecordunknown\n* line 1686 of /lib/dml/moodle_database.php: dml_missing_record_exception thrown\n* line 694 of /question/engine/bank.php: call to moodle_database->get_record_sql()\n* line 600 of /cache/classes/loaders.php: call to question_finder->load_for_cache()\n* line 418 of /cache/classes/loaders.php: call to cache->get_implementation()\n* line 530 of /question/engine/bank.php: call to cache->get()\n* line 257 of /question/engine/bank.php: call to question_finder->load_question_data()\n* line 275 of /question/engine/bank.php: call to question_bank::load_question_data()\n* line 190 of /mod/quiz/locallib.php: call to question_bank::load_question()\n* line 2057 of /mod/quiz/locallib.php: call to quiz_start_new_attempt()\n* line 110 of /mod/quiz/startattempt.php: call to quiz_prepare_and_start_new_attempt()\n, referer: https://our.flinders.vic.edu.au/mod/quiz/view.php?id=1911116

I'll also add a video of the issue. 

What could be wrong?

Attachment Cant find data record in database.png
Average of ratings: -
In reply to Michael Woods

Re: "Can't find data record in database" when attempting to preview Quiz

by Michael Woods -
Picture of Core developers
Okay, so I can see that the following query is returning no records, however, there *is* a record on mdl_question with an ID of 1088783. I'll dig some more.

We are a very old Moodle site, having started with version 1.8, and some of the longer-serving teachers created quizzes back then (2007). I suspect perhaps the Question Categories have now caused some issues in the latest upgrade?

SELECT
q.id
   ,qc.id AS category
   ,q.parent
   ,q.name
   ,q.questiontext
   ,q.questiontextformat
   ,q.generalfeedback
   ,q.generalfeedbackformat
   ,q.defaultmark
   ,q.penalty
   ,q.qtype
   ,q.length
   ,q.stamp
   ,q.timecreated
   ,q.timemodified
   ,q.createdby
   ,q.modifiedby
   ,qbe.idnumber
   ,qc.contextid
   ,qv.status
   ,qv.id AS versionid
   ,qv.version
   ,qv.questionbankentryid
FROM mdl_question q
JOIN mdl_question_versions qv
ON qv.questionid = q.id
JOIN mdl_question_bank_entries qbe
ON qbe.id = qv.questionbankentryid
JOIN mdl_question_categories qc
ON qc.id = qbe.questioncategoryid
WHERE q.id = 1088783;
In reply to Michael Woods

Re: "Can't find data record in database" when attempting to preview Quiz

by Michael Woods -
Picture of Core developers
So, post-upgrade to 4.3, it seems that the questions are pointing to categories that no longer exist.

When I click to preview or edit the below question:


I get this error:


Does anyone know how this might have happened? Or is there a SQL patch?
In reply to Michael Woods

Re: "Can't find data record in database" when attempting to preview 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 am not sure. I supposed it is possible that these questions where in categories that did not exist even before the upgrade, but the Moodle code used not to care about that.

(If you have a backup of the site before the upgrade, I guess it would be possible to restore the backup and see if that guess is true, but I am not sure if doing that is worth the effort.) mdl_question_bank_entries which refer to a category that does not exist, and then update them to point to a category that does exist. That might work? (If possible test anything on a backup copy of your real site before doing direct DB changes.)

I suppose if you wanted to try to fix this, you could do a query to find
In reply to Tim Hunt

Re: "Can't find data record in database" when attempting to preview Quiz

by Michael Woods -
Picture of Core developers
Thanks, Tim. Appreciate your response.