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

error_question_answers_missing_in_db when duplicate or restore quiz

      Since the update from Moodle 4.4.3 to 4.4.4, we get this error when duplicating a quiz or if we perform a restore by overwriting the course (this doesn’t happen when we use the option to delete the course before restoring).

      Here is an example of the error we get:

      Failed to find an answer matching ‘conditional answer’ in the question_answers database table. 
      This occurred while restoring the question with id 6889 in the backup file, which has been matched to the existing question with id 6904 in the database. 

      The problem is due to a change made in MDL-77625, in the file /backup/util/dbops/restore_dbops.class.php:

      Before the modification, the question version was taken into account in this if statement:

      if (isset($questioncache[$question->stamp." ".$question->version])) {
          $matchqid = $questioncache[$question->stamp." ".$question->version];
      } else {
          $matchqid = false;
      } 

      After the fix, only the stamp is checked:

      if (isset($questioncache[$question->stamp])) {
          $matchqid = $questioncache[$question->stamp];
      } else {
          $matchqid = false;
      } 

      In our question bank, we have questions with repeated stamps. I don’t know why this happens or if it’s normal, but there seem to be more people facing this same issue with questions that have the same stamp.

      I have verified that taking the version into account again in that if statement solves the problem, and we can duplicate and perform restores without any issues.
      To reproduce the issue, I can’t provide steps to get questions with the same stamp, but if you manage to reach this state, to get the error you only need to:

      In a course with a question bank that contains questions with the same stamp:

      1.Create a quiz.

      2.Add a question to the quiz.

      3.Duplicate the quiz.

      4.You’ll get the error I’ve mentioned.

        1. 83541 dev test - manual.png
          83541 dev test - manual.png
          124 kB
        2. 83541 dev test - phpunit.png
          83541 dev test - phpunit.png
          25 kB
        3. After2cloning20250121.png
          After2cloning20250121.png
          8 kB
        4. After Cloning2.png
          After Cloning2.png
          11 kB
        5. After Cloning-2.png
          After Cloning-2.png
          11 kB
        6. After Cloning20250121.png
          After Cloning20250121.png
          12 kB
        7. After Cloning20250121-1.png
          After Cloning20250121-1.png
          12 kB
        8. Before Cloning.png
          Before Cloning.png
          6 kB
        9. Before Cloning-1.png
          Before Cloning-1.png
          6 kB
        10. Before Cloning20250116.png
          Before Cloning20250116.png
          11 kB
        11. double_question_20250121.png
          double_question_20250121.png
          11 kB
        12. image-2024-10-28-12-22-46-360.png
          image-2024-10-28-12-22-46-360.png
          12 kB
        13. import_errors_qb_stamp_duplication.mp4
          16.33 MB

            Created:
            Updated:

              Estimated:
              Original Estimate - 0 minutes
              0m
              Remaining:
              Remaining Estimate - 0 minutes
              0m
              Logged:
              Time Spent - 5 hours, 30 minutes
              5h 30m

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