Question Preview: Can't find data record in database table context

Question Preview: Can't find data record in database table context

Nicholas Fahey
Number of replies: 5

After migrating from 3.11 to 4.0.1, 

Trying to preview questions in quiz or question bank brings back this error message for all question types:


Can't find data record in database table context.

More information about this error

Debug info: SELECT * FROM {context} WHERE id = ?
[array (
0 => 1,
)]
Error code: invalidrecord×Dismiss this notification
Stack trace:
line 1646 of /lib/dml/moodle_database.php: dml_missing_record_exception thrown
line 1622 of /lib/dml/moodle_database.php: call to moodle_database->get_record_select()
line 5353 of /lib/accesslib.php: call to moodle_database->get_record()
line 136 of /comment/lib.php: call to context::instance_by_id()
line 96 of /question/bank/comment/lib.php: call to comment->__construct()
line 7989 of /lib/moodlelib.php: call to qbank_comment_preview_display()
line 265 of /question/bank/previewquestion/classes/helper.php: call to component_callback()
line 286 of /question/bank/previewquestion/preview.php: call to qbank_previewquestion\helper::get_preview_extra_elements()


I do not have access to the server, as I'm purchasing hosting. Any insight would be helpful that I can pass on to the company, or troubleshooting I can do from the site admin would be helpful!

평균 등급 : -
In reply to Nicholas Fahey

Re: Question Preview: Can't find data record in database table context

Nicholas Fahey
FYI, cron is running every minute:

Cleaning up old question previews...done.
... used 2 dbqueries
... used 0.006756067276001 seconds
Scheduled task complete: Background processing for cleaning up question previews (core\task\question_preview_cleanup_task)


I can preview an entire quiz, just not individual questions from the bank.
In reply to Nicholas Fahey

Re: Question Preview: Can't find data record in database table context

Leon Stringer
Core developers 사진 Particularly helpful Moodlers 사진

This could be a bug caused by an assumption in question/bank/comment/lib.php:qbank_comment_preview_display() that there must be a row in mdl_context with id = 1 which may not be the case.

Try changing line 87 of question/bank/comment/lib.php from:

        $args->contextid = 1; // Static data to bypass comment sql as context is not needed.

to:

        $args->contextid = context_system::instance()->id;
평균 등급 :Useful (1)
In reply to Leon Stringer

Re: Question Preview: Can't find data record in database table context

Nicholas Fahey
Thank you Leon! That did the trick.

Only now the question previews are no longer opening as pop-ups. I can right click and open them in a new tab, but not ideal. Any suggestions?
In reply to Nicholas Fahey

Re: Question Preview: Can't find data record in database table context

Leon Stringer
Core developers 사진 Particularly helpful Moodlers 사진

If you open your browser's developer tools and look in the console (for example Web Console in Firefox) and then click on the Preview queston icon are any error messages shown in the console?

In reply to Leon Stringer

Re: Question Preview: Can't find data record in database table context

Leon Stringer
Core developers 사진 Particularly helpful Moodlers 사진

I've reported the Can't find data record in database table context error on question preview as MDL-75631.