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

Quiz questions instance with duplicate question IDs cause fatal upgrade error

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Critical
    • Resolution: Fixed
    • Affects Version/s: 2.7
    • Fix Version/s: 2.7.1
    • Component/s: Quiz
    • Labels:
    • Testing Instructions:
      Hide
      1. Create a quiz in a Moodle 2.6 instance.
      2. Add a question to the quiz
      3. In the quiz_question_instances table, insert multiple records with a quiz id matching your quiz, a question of 0, and a maxmark of 0.
      4. In the quiz_question_instances table, insert multiple records with a quiz id matching your quiz, and question/maxmark values matching the question you inserted.
      5. Upgrade to Moodle 2.7
      6. Confirm that only 1 record for your questionid (and none for question id 0) still exist quiz_slots for your quiz after upgrade. If debugging it on, you expect to see one or twos warning during the quiz upgrade - unused questions, and updating sumgrade.
      Show
      Create a quiz in a Moodle 2.6 instance. Add a question to the quiz In the quiz_question_instances table, insert multiple records with a quiz id matching your quiz, a question of 0, and a maxmark of 0. In the quiz_question_instances table, insert multiple records with a quiz id matching your quiz, and question/maxmark values matching the question you inserted. Upgrade to Moodle 2.7 Confirm that only 1 record for your questionid (and none for question id 0) still exist quiz_slots for your quiz after upgrade. If debugging it on, you expect to see one or twos warning during the quiz upgrade - unused questions, and updating sumgrade.
    • Affected Branches:
      MOODLE_27_STABLE
    • Fixed Branches:
      MOODLE_27_STABLE

      Description

      If the question_instance records for a contain the same question id (column question) two or more times, they will not be cleaned up during the upgrade and will cause an error:

      Something went wrong in the quiz upgrade step for MDL-43749.
      Some quiz_slots still contain NULLs which will break the NOT NULL constraints we need to add. 
      Please report this problem at http://tracker.moodle.org/ so that it can be investigated. Thank you.
      

      I'm not sure how this happens, but we have a few cases of this in our production DB. One of them, each question in the quiz has two records, in another, they have bunch of question id = 0, which I believe is the old flag for a page break.

      I tracked it down to version 2014022003 code block in mod/quiz/db/upgrade.php. It uses the questionid column as the unique key, so that causes duplicates to be missed, and during the cleanup (around line 650), only at most one of them will be removed.

        Attachments

          Issue Links

            Activity

              People

              • Votes:
                0 Vote for this issue
                Watchers:
                5 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:
                  Fix Release Date:
                  14/Jul/14