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

error_question_answers_missing_in_db when duplicate or restore quiz

XMLWordPrintable

    • MOODLE_403_STABLE, MOODLE_404_STABLE
    • MOODLE_404_STABLE, MOODLE_405_STABLE
    • MDL-83541-404
    • MDL-83541-405
    • MDL-83541-main
    • Hide

      This is covered by automated tests in mod/quiz/tests/backup/repeated_restore_test.php and backup/tests/quiz_restore_decode_links_test.php, which also cover questions with edited hints, edited qtype-specific fields, and encoded links in the question and answer text.

      Setup:

      • Create a course with 2 quizzes, each containing 1 multiple-choice question (the answers to these 2 questions must be different).
      • Modify the `stamp` value in the mdl_question table so that either quiz1 or quiz2 to have the same value.

      Test duplicating quiz:

      • Go to the course preview on edit mode
      • Click the little three dots > Select "Duplicate"
      • The quiz should be able to be duplicated without error

      Test restoring quiz:

      • Select one of the quiz > More > Backup > proceed with the default setting
      • Ensure the cronjob is running to let the backup works
      • Select one of the quiz > More > Restore > select Restore on the backup made earlier
      • Ensure the cronjob is running to let the restoring works
      • A new quiz should be restored without error
      Show
      This is covered by automated tests in mod/quiz/tests/backup/repeated_restore_test.php and backup/tests/quiz_restore_decode_links_test.php, which also cover questions with edited hints, edited qtype-specific fields, and encoded links in the question and answer text. Setup: Create a course with 2 quizzes, each containing 1 multiple-choice question (the answers to these 2 questions must be different). Modify the `stamp` value in the mdl_question table so that either quiz1 or quiz2 to have the same value. Test duplicating quiz: Go to the course preview on edit mode Click the little three dots > Select "Duplicate" The quiz should be able to be duplicated without error Test restoring quiz: Select one of the quiz > More > Backup > proceed with the default setting Ensure the cronjob is running to let the backup works Select one of the quiz > More > Restore > select Restore on the backup made earlier Ensure the cronjob is running to let the restoring works A new quiz should be restored without error
    • Hide

      Code verified against automated checks.

      Checked MDL-83541 using repository: https://github.com/marxjohnson/moodle

      More information about this report

      Built on: Tue Feb 18 05:58:37 PM UTC 2025

      Show
      Code verified against automated checks. Checked MDL-83541 using repository: https://github.com/marxjohnson/moodle MOODLE_404_STABLE (0 errors / 0 warnings) [branch: MDL-83541_404_STABLE | CI Job ] MOODLE_405_STABLE (0 errors / 0 warnings) [branch: MDL-83541_405_STABLE | CI Job ] main (0 errors / 0 warnings) [branch: MDL-83541_main | CI Job ] More information about this report Built on: Tue Feb 18 05:58:37 PM UTC 2025
    • Hide

      Launching automatic jobs for branch MDL-83541-404

      Launching automatic jobs for branch MDL-83541-405

      Launching automatic jobs for branch MDL-83541-main

      Built on: Fri Mar 14 03:32:51 UTC 2025

      Show
      Launching automatic jobs for branch MDL-83541 -404 https://ci.moodle.org/view/Testing/job/DEV.02%20-%20Developer-requested%20PHPUnit/18588/ PHPUnit (sqlsrv / complete) Launching automatic jobs for branch MDL-83541 -405 https://ci.moodle.org/view/Testing/job/DEV.02%20-%20Developer-requested%20PHPUnit/18589/ PHPUnit (sqlsrv / complete) Launching automatic jobs for branch MDL-83541 -main https://ci.moodle.org/view/Testing/job/DEV.02%20-%20Developer-requested%20PHPUnit/18590/ PHPUnit (sqlsrv / complete) Built on: Fri Mar 14 03:32:51 UTC 2025

      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.

       

      — Replicate steps by Mark —

      1. Install Moodle 3.11.
      2. Create a new course "Test course 1".
      3. Go the the course's question bank and create a new multiple choice question "Test question 1" with several answers.
      4. Create a copy of the course, "Test course 2".
      5. Go to the "Test course 2" question bank, edit "Test question 1" and change the answers.
      6. From the "Test course 2" question bank, select "Test question 1" and move it to the "Default for system" question category.
      7. Go to the "Test course 1" question bank, switch to the "Default for system" question category select "Test question 1", and move it to the "Default for Test course 1" category.
        • You will now have two questions called "Test question 1" in the same context, with the same stamp but different answers.
      8. Upgrade to Moodle 4.1.
      9. Upgrade to Moodle 4.5 (requires upgrading PHP version).
      10. Go to "Test course 1"
      11. Create a quiz and add one of the instances of "Test question 1" to the quiz.
      12. Duplicate the quiz
        • The error is displayed.

        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. benchmark_test_stable.php
          7 kB
        12. benchmark_test.php
          7 kB
        13. cleanup_after_duplicates_cli_global_context_final.php
          12 kB
        14. cleanup_after_duplicates_cli_global_context_final-fixed.php
          12 kB
        15. cleanup_duplicates_context_cli_global_final.php
          22 kB
        16. cleanup_duplicates_context_cli_global_final-1.php
          22 kB
        17. double_question_20250121.png
          double_question_20250121.png
          11 kB
        18. image-2024-10-28-12-22-46-360.png
          image-2024-10-28-12-22-46-360.png
          12 kB
        19. image-2025-01-29-16-38-18-438.png
          image-2025-01-29-16-38-18-438.png
          143 kB
        20. import_errors_qb_stamp_duplication.mp4
          16.33 MB
        21. MDL-83541_benchmarks.ods
          18 kB
        22. MDL-83541.png
          MDL-83541.png
          186 kB

            Created:
            Updated:
            Resolved:

              Estimated:
              Original Estimate - 0 minutes
              0m
              Remaining:
              Remaining Estimate - 0 minutes
              0m
              Logged:
              Time Spent - 1 day, 5 hours, 17 minutes
              1d 5h 17m

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