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

Error when duplicating a Quiz and moving it to another section with different visibility



    • Type: Bug
    • Status: Open
    • Priority: Minor
    • Resolution: Unresolved
    • Affects Version/s: 3.6.2
    • Fix Version/s: None
    • Component/s: Course, Quiz
    • Labels:
    • Affected Branches:


      Hi, I'm experiencing a strange behavior and I've done a lot of investigation in order to understand the scenario.

      It all started few days ago, after I have upgraded our installation from 3.5.4 to 3.6.2.

      When moving a copy of a Quiz from a section to another with different visibility, an inconsistency is created with course modules. After that, if you open it you'll get an error page (see the attached image named Moved quiz (copy) Exception.png).

      You'll also get an error entering in any other quiz or activity in the same course that has grading (ie. Assign) and also entering the Gradebook. Any other activity without grading (ie. Forum) works fine.

      Thinking about a caching error, I've tried to purge caches, restart apache or mysql but none of these solved the error.

      I've found that executing the CLI script fix_course_sequence.php solves the problem. After that I've cheched the course_sections table and, just after moving, the course module id of the moved quiz is missing from any section sequence (before moving it is correctly present in the original section).

      The fix_course_sequence.php essentially calls two methods:
      - course_integrity_check
      - rebuild_course_cache

      Said that, the section sequence error could be a side effect but something inside course_integrity_check and rebuild_course_cache solve the problem. Calling them separately doesn't solve the problem. You need to call them both.

      Now, after writing a bible, I'll write instruction to reproduce the problem.

      You need a course with two o more sections in a course, with at least one visible and one hidden.

      Steps to reproduce the error:

      1. Create a visible Quiz in the visible section (the questions inside the quiz are not needed)
      2. Duplicate the Quiz
      3. Move the copy from the visible section to the hidden section
      4. Open the Quiz and you'll get an Invalid course module ID error page (see the attached image named Moved quiz (copy) Exception.png)
      5. Turn back to the course and open the original quiz. You'll get again an Invalid course module ID error page but with different stack trace (see the attached image named Other quizzes Exception.png). 
      6. Turn back to the course and open the gradebook. You'll get the previous error page.

      Variants that DO NOT cause the error:

      • After step 2 and before step 3
        • Open the copy
        • Turn back to the course
      • After step 2 and before step 3
        • Open the gradebook
        • Turn back to the course
      • After step 1 and before step 2
        • Change the visibility of the created quiz to hidden
      • Instead of step 3
        • Move the copy from the current section to another with the same visibility





            kemmotar Giorgio Riva
            Component watchers:
            Amaia Anabitarte, Carlos Escobedo, Ferran Recio, Sara Arjona (@sarjona), Víctor Déniz Falcón, Tim Hunt, Andrew Nicols, Jun Pataleta, Michael Hawkins, Shamim Rezaie, Simey Lameze
            1 Vote for this issue
            6 Start watching this issue



                Time Tracking

                Original Estimate - Not Specified
                Not Specified
                Remaining Estimate - 0 minutes
                Time Spent - 10 minutes