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

Editing a quiz with section headings can cause a unique key violation

    XMLWordPrintable

Details

    • Bug
    • Status: Closed
    • Minor
    • Resolution: Fixed
    • 3.1.3, 3.3.1
    • 3.2.6, 3.3.3
    • Quiz
    • MOODLE_31_STABLE, MOODLE_33_STABLE
    • MOODLE_32_STABLE, MOODLE_33_STABLE
    • Hide

      Please test this issue on both postgres and mysql databases. You may only be able to confirm the bug on mysql

      1. Create a quiz like this
        • Section heading 1
        • Question 1
        • Section heading 2
        • Question 2
        • Section heading 3
        • Question 3
      2. Add a new question on page 1.
      3. The question should be added with no errors.
      4. Reload the page, and verify that what appear really does not change. (This checks for discrepancies between udpates done to the page by JavaScript code, and what happens when the page is re-generated fresh from the database.)
      5. Move the new question from Page 1 to after Question 3.
      6. Verify that the display updates with no errors.
      7. Reload the page, and verify that what appear really does not change.
      8. Move the new question back to Page 1.
      9. Verify that the display updates with no errors.
      10. Reload the page, and verify that what appear really does not change.
      11. Remove the new question from the quiz.
      12. Verify that the display updates with no errors.
      13. Reload the page, and verify that what appear really does not change.
      Show
      Please test this issue on both postgres and mysql databases. You may only be able to confirm the bug on mysql Create a quiz like this Section heading 1 Question 1 Section heading 2 Question 2 Section heading 3 Question 3 Add a new question on page 1. The question should be added with no errors. Reload the page, and verify that what appear really does not change. (This checks for discrepancies between udpates done to the page by JavaScript code, and what happens when the page is re-generated fresh from the database.) Move the new question from Page 1 to after Question 3. Verify that the display updates with no errors. Reload the page, and verify that what appear really does not change. Move the new question back to Page 1. Verify that the display updates with no errors. Reload the page, and verify that what appear really does not change. Remove the new question from the quiz. Verify that the display updates with no errors. Reload the page, and verify that what appear really does not change.

    Description

      The problem only arises if you have sections with only one question in them.

      Steps to reproduce (other thhings can trigger this too):

      # Create a quiz like this

        • Section heading 1
        • Question 1
        • Section heading 2
        • Question 2
        • Section heading 3
        • Question 3
      1. Add a new question immediately after Question 1.

      Expected result: it works.

      Actual result, at least on Postgres and MySQL: Unique key violation [quizid]-3.

      (See https://docs.moodle.org/en/Building_Quiz#Section_headings about how to add sections)

      See this forum thread https://moodle.org/mod/forum/discuss.php?d=343696.

      This MySQL-only work-around in the SQL would solve it: https://www.xaprb.com/blog/2006/06/16/how-to-avoid-unique-index-violations-on-updates-in-mysql/.

      However, since this affects other databases too, we need to use update_field_with_unique_index.

      Attachments

        Issue Links

          Activity

            People

              timhunt Tim Hunt
              timhunt Tim Hunt
              Shamim Rezaie Shamim Rezaie
              Jake Dallimore Jake Dallimore
              Ryan Wyllie Ryan Wyllie
              Tim Hunt, Andrew Lyons, Huong Nguyen, Jun Pataleta, Michael Hawkins, Shamim Rezaie, Simey Lameze, Stevani Andolo
              Votes:
              3 Vote for this issue
              Watchers:
              15 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:
                13/Nov/17