Uploaded image for project: 'Moodle'
  1. Moodle
  2. MDL-75631

Can't find data record in database table context when previewing questions

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: Minor Minor
    • None
    • 4.0.3
    • Questions
    • None
    • MOODLE_400_STABLE

      If the system contextlevel (10) is not id = 1 in mdl_context then you get an error when you try to preview questions: "Can't find data record in database table context.".

      Steps to reproduce issue

      1. Set up a Moodle 4.0 site.
      2. Edit the database to simulate the system contextlevel having ID ≠ 1:
        1. DELETE FROM mdl_context WHERE id = 1;
        2. INSERT INTO mdl_context (contextlevel, path, depth) VALUES (10, '/1', 1);
      3. Rebuild the context paths following step B (in short: change line 49 of lib/classes/task/context_cleanup_task.php to true, then run \core\task\context_cleanup_task).
      4. Purge caches using the command line (for example: sudo -u apache php admin/cli/purge_caches.php).
      5. Add a course.
      6. Add a quiz to the course.
      7. Add a question to the quiz.
      8. Click the magnifying glass icon (Preview question).

      Expected results

      A window pops up showing the preview of the question.

      Actual results

      The error message "Can't find data record in database table context." appears in red. With debugging enabled:

      Debug info: SELECT * FROM {context} WHERE id = ?
      [array (
      0 => 1,
      )]
      Error code: invalidrecord
      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 8013 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()

            Unassigned Unassigned
            leonstr Leon Stringer
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved:

                Error rendering 'clockify-timesheets-time-tracking-reports:timer-sidebar'. Please contact your Jira administrators.