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

Error when duplicating a question with an IDnumber

    XMLWordPrintable

Details

    • Bug
    • Status: Closed
    • Minor
    • Resolution: Fixed
    • 3.6
    • 3.6.2
    • Questions
    • MOODLE_36_STABLE
    • MOODLE_36_STABLE
    • Hide
      1. Go to the question bank in any course.
      2. Create a new true-false question. As you do, set the Id number to 'frog'.
      3. In the question bank, click the 'Duplicate' icon.
      4. Without changing anything, save the new questions.
      5. Verify that the duplicate question is saved. (Before this fix, there would been a form validation error about a duplicate idnumber.)
      6. Duplicate the question that was previously duplicated.
      7. Confirm that a new duplicate is created successfully.
      Show
      Go to the question bank in any course. Create a new true-false question. As you do, set the Id number to 'frog'. In the question bank, click the 'Duplicate' icon. Without changing anything, save the new questions. Verify that the duplicate question is saved. (Before this fix, there would been a form validation error about a duplicate idnumber.) Duplicate the question that was previously duplicated. Confirm that a new duplicate is created successfully.

    Description

      Starting with Moodle 3.6, questions can have an ID number (which must be unique within a given category). This results in a bug when duplicating a question with an ID if the user forgets to give the duplicated question a different ID. I would have reported this in the tracker, but I've lost touch with it for a few years. I hope the info below will be useful for someone to create a bug report.

      My original question had an ID number = 99.

      Error writing to database

      Debug info: Duplicate entry '2-99' for key 'mdl_ques_catidn_uix'
      INSERT INTO mdl_question

      etc.

      Stack trace:

      • line 489 of \lib\dml\moodle_database.php: dml_write_exception thrown
      • line 1329 of \lib\dml\mysqli_native_moodle_database.php: call to moodle_database->query_end()
      • line 1375 of \lib\dml\mysqli_native_moodle_database.php: call to mysqli_native_moodle_database->insert_record_raw()
      • line 372 of \question\type\questiontypebase.php: call to mysqli_native_moodle_database->insert_record()
      • line 273 of \question\question.php: call to question_type->save_question()

      Note: First reported in the Quiz forum at https://moodle.org/mod/forum/discuss.php?d=379434#p1529695

      Attachments

        Activity

          People

            timhunt Tim Hunt
            rezeau Joseph Rézeau
            Joseph Rézeau Joseph Rézeau
            Jun Pataleta Jun Pataleta
            Anna Carissa Sadia Anna Carissa Sadia
            Tim Hunt, Andrew Lyons, Huong Nguyen, Jun Pataleta, Michael Hawkins, Shamim Rezaie, Simey Lameze
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:
              14/Jan/19

              Time Tracking

                Estimated:
                Original Estimate - Not Specified
                Not Specified
                Remaining:
                Remaining Estimate - 0 minutes
                0m
                Logged:
                Time Spent - 10 minutes
                10m