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

Error when duplicating Quizzes in certain cases

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: Major Major
    • 3.11.5
    • 3.9.10, 3.10.7, 3.11.3
    • Course, Quiz
    • MOODLE_310_STABLE, MOODLE_311_STABLE, MOODLE_39_STABLE
    • MOODLE_311_STABLE
    • MDL-72771_master
    • Hide
      1. Create a new course
      2. Enrol one student
      3. Hide one topic
      4. In a visible topic, create a new quiz (no need to add any questions)
      5. Configure new quiz with activity completion set to Show activity as complete when conditions are met > Student must receive a grade to complete this activity
      6. Go to course grades, turn editing on and grade the student for the quiz you just create.
      7. Return to the course and turn editing on
      8. Duplicate the quiz
      9. Move the duplicated quiz to the hidden topic using the move arrow
      10. Check you can access the new quiz
      Show
      Create a new course Enrol one student Hide one topic In a visible topic, create a new quiz (no need to add any questions) Configure new quiz with activity completion set to Show activity as complete when conditions are met > Student must receive a grade to complete this activity Go to course grades, turn editing on and grade the student for the quiz you just create. Return to the course and turn editing on Duplicate the quiz Move the duplicated quiz to the hidden topic using the move arrow Check you can access the new quiz

      So as reported in MDL-64868 (closed as inactive), there is a certain case that can complete break a quiz when you duplicate it. Although there was a specific step that ticket didn't have that is currently required to reproduce it.

      1. Have a topic that is visible, and one that is hidden
      2. In the visible category, create a quiz with activity completion set to Show activity as complete when conditions are met > Student must receive a grade to complete this activity. You don't need to add anything to the quiz/do anything with it.
      3. Duplicate the quiz
      4. Without reloading the page, move the duplicate quiz to the hidden category using the move arrow
      5. Now try to access new quiz.

      I have confirmed on the latest 3.11.3+ that you will see:

      Invalid course module ID
      More information about this error
      Debug info:
      Error code: invalidcoursemodule
      Stack trace:
      * line 236 of /lib/modinfolib.php: moodle_exception thrown
      * line 2677 of /lib/moodlelib.php: call to course_modinfo->get_cm()
      * line 56 of /mod/quiz/view.php: call to require_login()
      

      Basically the module no longer exists in a course_section record (and especially not one that matches its course_modules section value).

      If you have enough debugging on, you can see that during the rest call to move the module, this happened:

      Invalid course module ID
      invalidcoursemodule
      * line 236 of /lib/modinfolib.php: moodle_exception thrown
      * line 1890 of /lib/modinfolib.php: call to course_modinfo->get_cm()
      * line 1041 of /lib/completionlib.php: call to cm_info::create()
      * line 623 of /lib/completionlib.php: call to completion_info->get_data()
      * line 1434 of /lib/completionlib.php: call to completion_info->update_state()
      * line 1203 of /lib/grade/grade_grade.php: call to completion_info->inform_grade_changed()
      * line 367 of /lib/grade/grade_object.php: call to grade_grade->notify_changed()
      * line 1033 of /lib/grade/grade_grade.php: call to grade_object->insert()
      * line 653 of /lib/grade/grade_category.php: call to grade_grade->insert()
      * line 567 of /lib/grade/grade_category.php: call to grade_category->aggregate_grades()
      * line 809 of /lib/grade/grade_item.php: call to grade_category->generate_grades()
      * line 1276 of /lib/gradelib.php: call to grade_item->regrade_final_grades()
      * line 448 of /lib/gradelib.php: call to grade_regrade_final_grades()
      * line 812 of /mod/quiz/lib.php: call to grade_get_grades()
      * line 7917 of /lib/moodlelib.php: call to quiz_grade_item_update()
      * line 915 of /course/lib.php: call to component_callback()
      * line 1752 of /course/lib.php: call to set_coursemodule_visible()
      * line 86 of /course/rest.php: call to moveto_module()
      

      The root of the problems seems to be in course/lib.php::moveto_module(). The problem is that the function first removes the module from the section, which is now an invalid DB state, and then updates visibility, before finally placing it into the new section.

      The important part is that you shouldn't call set_coursemodule_visible() while the DB is in an invalid state.

        1. MDL-72771_v310.webm
          267 kB
        2. MDL-72771_v311.webm
          454 kB
        3. MDL-72771_v39.webm
          372 kB
        4. MDL-72771 testing.webm
          572 kB

            reskit Marc Català
            emerrill Eric Merrill
            Tim Hunt Tim Hunt
            Sara Arjona (@sarjona) Sara Arjona (@sarjona)
            Angelia Dela Cruz Angelia Dela Cruz
            Votes:
            6 Vote for this issue
            Watchers:
            13 Start watching this issue

              Created:
              Updated:
              Resolved:

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

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