Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Missing question causes invalidrecordunknown error, on MY (dashboard) page #7

Open
nadavkav opened this issue Nov 21, 2023 · 3 comments

Comments

@nadavkav
Copy link

Teacher A was using a question with a quizquestion availability condition on one of the course modules,
and then, another Teacher (B) in the same course deleted it from one of the question banks in a course.
Now, when either of them viewed the MY (dashboard) page,
They got the following JS dialog error: invalidrecordunknown

We are using Moodle 4.1.6 with availability_quizquestion version 1.3 (2022092000)

See full error, with DEBUG turned ON:

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 {question} q
JOIN {question_versions} qv ON qv.questionid = q.id
JOIN {question_bank_entries} qbe ON qbe.id = qv.questionbankentryid
JOIN {question_categories} qc ON qc.id = qbe.questioncategoryid
WHERE q.id = :id
[array (
'id' => 73357,
)]
Error code: invalidrecordunknown

  • line 1682 of /lib/dml/moodle_database.php: dml_missing_record_exception thrown
  • line 670 of /question/engine/bank.php: call to moodle_database->get_record_sql()
  • line 587 of /cache/classes/loaders.php: call to question_finder->load_for_cache()
  • line 1870 of /cache/classes/loaders.php: call to cache->get_implementation()
  • line 405 of /cache/classes/loaders.php: call to cache_application->get_implementation()
  • line 526 of /question/engine/bank.php: call to cache->get()
  • line 255 of /question/engine/bank.php: call to question_finder->load_question_data()
  • line 216 of /availability/condition/quizquestion/classes/condition.php: call to question_bank::load_question_data()
  • line 144 of /availability/condition/quizquestion/classes/condition.php: call to availability_quizquestion\condition->update_question_id_to_question_bank_entry_id_if_required()
  • line 128 of /availability/condition/quizquestion/classes/condition.php: call to availability_quizquestion\condition->requirements_fulfilled()
  • line 84 of /availability/classes/condition.php: call to availability_quizquestion\condition->is_available()
  • line 265 of /availability/classes/tree.php: call to core_availability\condition->check_available()
  • line 197 of /availability/classes/info.php: call to core_availability\tree->check_available()
  • line 2275 of /lib/modinfolib.php: call to core_availability\info->is_available()
  • line 1746 of /lib/modinfolib.php: call to cm_info->obtain_dynamic_data()
  • line 1224 of /lib/completionlib.php: call to cm_info->get_custom_data()
  • line 1073 of /lib/completionlib.php: call to completion_info->get_other_cm_completion_data()
  • line 82 of /completion/classes/progress.php: call to completion_info->get_data()
  • line 210 of /course/classes/external/course_summary_exporter.php: call to core_completion\progress::get_course_progress_percentage()
  • line 62 of /course/classes/external/course_summary_exporter.php: call to core_course\external\course_summary_exporter::get_course_progress()
  • line 125 of /lib/classes/external/exporter.php: call to core_course\external\course_summary_exporter->get_other_values()
  • line 3942 of /course/externallib.php: call to core\external\exporter->export()
  • line ? of unknownfile: call to core_course_external::{closure}()
  • line 3943 of /course/externallib.php: call to array_map()
  • line 244 of /blocks/myoverview/classes/external.php: call to core_course_external::get_enrolled_courses_by_timeline_classification()
  • line 262 of /lib/externallib.php: call to block_myoverview_external::get_enrolled_courses_by_timeline_classification()
  • line 81 of /lib/ajax/service.php: call to external_api::call_external_function()
@nadavkav
Copy link
Author

Here is an SQL query that helped us identify all the question ids that are used in availability conditions which have deleted questions.

SELECT cm.id, cm.course, cm.module, cm.instance
    ,m.name
    ,CASE m.name
         WHEN 'assign' THEN (SELECT asg.name FROM mdl_assign AS asg WHERE asg.id = cm.instance)
         WHEN 'forum' THEN (SELECT f.name FROM mdl_forum AS f WHERE f.id = cm.instance)
         WHEN 'quiz' THEN (SELECT q.name FROM mdl_quiz AS q WHERE q.id = cm.instance)
         WHEN 'questionnaire' THEN (SELECT q.name FROM mdl_questionnaire AS q WHERE q.id = cm.instance)
         WHEN 'hvp' THEN (SELECT q.name FROM mdl_hvp AS q WHERE q.id = cm.instance)
         WHEN 'resource' THEN (SELECT q.name FROM mdl_resource AS q WHERE q.id = cm.instance)
         WHEN 'page' THEN (SELECT q.name FROM mdl_page AS q WHERE q.id = cm.instance)
         WHEN 'folder' THEN (SELECT q.name FROM mdl_folder AS q WHERE q.id = cm.instance)
         WHEN 'ejsapp' THEN (SELECT q.name FROM mdl_ejsapp AS q WHERE q.id = cm.instance)
         WHEN 'url' THEN (SELECT q.name FROM mdl_url AS q WHERE q.id = cm.instance)
         WHEN 'data' THEN (SELECT q.name FROM mdl_data AS q WHERE q.id = cm.instance)
         WHEN 'tab' THEN (SELECT q.name FROM mdl_tab AS q WHERE q.id = cm.instance)
         WHEN 'lesson' THEN (SELECT q.name FROM mdl_lesson AS q WHERE q.id = cm.instance)
    END AS 'oer name'
    ,JSON_EXTRACT(cm.availability, '$.c[0].quizid') AS 'avail_quizid'
    ,@questionids := TRIM(TRAILING ']' FROM TRIM(LEADING '[' FROM
        JSON_EXTRACT(cm.availability, '$.c[*].questionid'))) 'avail_questionid'
    ,(SELECT GROUP_CONCAT(q.id) FROM mdl_question AS q
      WHERE q.id IN (@questionids)) 'questionid_found'
    , cm.availability
FROM mdl_course_modules cm
JOIN mdl_modules m ON m.id = cm.module
WHERE cm.availability LIKE '%quizquestion%'

@nadavkav
Copy link
Author

Hi @timhunt , What are your thoughts about this issue?
As we are wondering how should we approach a solution to this

@avkeiller
Copy link

Hi @nadavkav
Thank you for providing the script to identify the deleted question.
In our case (v4.1.5), when we accessed the course, we encountered the error message.
We were able to initiate a backup/restore directly from the DB, but we also found that in some cases, the error can be resolved by
changing the position of the module in the category (Site Admin > Courses >> Manage courses and categories) - move the course up or down 1 position from the current.
In another case, clearing our REDIS cache also eliminated the error message.
Not sure if this is the same as the problem you are facing, but it has worked on our side and thought I'd share.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants