Moodle
  1. Moodle
  2. MDL-28643

Deleting module instance with completion tracking on grade causes errors

    Details

    • Testing Instructions:
      Hide

      EASY test instructions:

      0. Enable completion on site and course. Ensure debugging is set to max level (DEVELOPER) so you can see the message if it occurs. Ensure course AJAX is turned off because it sucks... er, I mean, so that you can see the message in normal browser window.
      1. Add new 'online text' assignment. Type in name, description. In completion section, choose automatic completion and tick the 'when student gets a grade' checkbox. Save and view.
      2. Click to submit the assignment yourself (as admin or whoever). Enter some text and save.
      3. Click the '1 submitted assignment' link and give the assignment a grade. Save grades.
      4. Go back to the course page and use the X button to delete the assignment. Confirm the prompt.

      Expected: Assignment is deleted without any error or warning.

      Show
      EASY test instructions: 0. Enable completion on site and course. Ensure debugging is set to max level (DEVELOPER) so you can see the message if it occurs. Ensure course AJAX is turned off because it sucks... er, I mean, so that you can see the message in normal browser window. 1. Add new 'online text' assignment. Type in name, description. In completion section, choose automatic completion and tick the 'when student gets a grade' checkbox. Save and view. 2. Click to submit the assignment yourself (as admin or whoever). Enter some text and save. 3. Click the '1 submitted assignment' link and give the assignment a grade. Save grades. 4. Go back to the course page and use the X button to delete the assignment. Confirm the prompt. Expected: Assignment is deleted without any error or warning.
    • Affected Branches:
      MOODLE_20_STABLE, MOODLE_21_STABLE, MOODLE_22_STABLE
    • Fixed Branches:
      MOODLE_20_STABLE, MOODLE_21_STABLE
    • Pull Master Branch:
      MDL-28643-master
    • Rank:
      18418

      Description

      When deleting a module instance that has activity completion tracking enabled the follow error is thrown:

      Couldn't find course-module for module '<modname>', instance '<instanceid>', course '<courseid>'

      line 803 of \lib\grade\grade_grade.php: call to debugging()
      line 262 of \lib\grade\grade_object.php: call to grade_grade->notify_changed()
      line 352 of \lib\grade\grade_item.php: call to grade_object->delete()
      line 336 of \lib\grade\grade_item.php: call to grade_item->delete_all_grades()
      line 1288 of \lib\gradelib.php: call to grade_item->delete()
      line 215 of \lib\adminlib.php: call to grade_uninstalled_module()
      line 94 of \admin\modules.php: call to uninstall_plugin()

      Then when later visting the course as a student who had achieved a completion record, the follow PHP notices are throw:

      Notice: Trying to get property of non-object in \lib\completionlib.php on line 898
      Notice: Trying to get property of non-object in \lib\completionlib.php on line 903
      Notice: Trying to get property of non-object in \lib\completionlib.php on line 912

      Replication instructions:

      1. Ensure debugging is turned on
      2. Turn off Ajax/JS in your profile
      3. Create an activity module instance (e.g. assignment)
      4. Set the completion to "achieve grade"
      5. Assign a grade to a student
      6. Run the cron manually by visiting /admin/cron.php
      7. Delete the module instance, or uninstall the module entirely (will throw debugging error)
      8. Visit the course as the student with the completion record (will throw PHP notices)

        Activity

        Hide
        Michael de Raadt added a comment -

        I was able to replicate the error message shown after the activity was deleted, but I was not able to reproduce the error messages shown to the student on the course page.

        Show
        Michael de Raadt added a comment - I was able to replicate the error message shown after the activity was deleted, but I was not able to reproduce the error messages shown to the student on the course page.
        Hide
        Sam Marshall added a comment -

        Oh dear.

        To clarify the subject: this will only apply for activities that are set to grade completion, not to other forms of completion. It looks like the 'delete grade' code updates the grade after the module has been deleted. When the module has completion tracking enabled, updating the grade requires the completion system to be informed. This is failing because the module has already been deleted.

        I'll look at this shortly.

        Show
        Sam Marshall added a comment - Oh dear. To clarify the subject: this will only apply for activities that are set to grade completion, not to other forms of completion. It looks like the 'delete grade' code updates the grade after the module has been deleted. When the module has completion tracking enabled, updating the grade requires the completion system to be informed. This is failing because the module has already been deleted. I'll look at this shortly.
        Hide
        Sam Marshall added a comment -

        Adjusting priority as this debugging message will not cause any problem (assignment is correctly deleted).

        Show
        Sam Marshall added a comment - Adjusting priority as this debugging message will not cause any problem (assignment is correctly deleted).
        Hide
        Sam Marshall added a comment -

        note: the fix I did means that it does not warn if it can't find the course-module when a grade is being deleted. This covers the case when a module is being deleted (also maybe other cases, but let's face it, it works then).

        Show
        Sam Marshall added a comment - note: the fix I did means that it does not warn if it can't find the course-module when a grade is being deleted. This covers the case when a module is being deleted (also maybe other cases, but let's face it, it works then).
        Hide
        Evan Irving-Pease added a comment -

        Hi Sam, thanks for the quick turnaround on this but I'm not convinced that suppressing the warning message on the delete action is going to solve this problem.

        To clarify the PHP notices that I get, these are not caused by the course itself, but rather the completionstatus block that is attached to the course. It would appear that the avtivity completion criteria expects the CM to still exist.

        Here's the full stack trace:

        # Time Memory Function Location
        1 0.0033 476432 {main}

        ( )

        ..\view.php:0
        2 1.2841 24325864 bootstrap_renderer->header( ) ..\view.php:196
        3 1.2841 24326016 bootstrap_renderer->__call( ) ..\setuplib.php:0
        4 1.2934 24424768 call_user_func_array ( ) ..\setuplib.php:1279
        5 1.2934 24424904 core_renderer->header( ) ..\setuplib.php:0
        6 1.3303 25061056 core_renderer->render_page_layout( ) ..\outputrenderers.php:612
        7 1.3311 25142168 include( 'theme\<themename>\layout\general.php' ) ..\outputrenderers.php:654
        8 1.7296 43198776 block_manager->region_has_content( ) ..\general.php:15
        9 1.7296 43198776 block_manager->ensure_content_created( ) ..\blocklib.php:349
        10 1.7296 43198896 block_manager->create_block_contents( ) ..\blocklib.php:972
        11 1.7436 43235416 block_base->get_content_for_output( ) ..\blocklib.php:920
        12 1.7436 43236608 block_base->formatted_contents( ) ..\moodleblock.class.php:232
        13 1.7436 43236608 block_completionstatus->get_content( ) ..\moodleblock.class.php:280
        14 1.7742 43377272 completion_criteria->is_pending( ) ..\block_completionstatus.php:116
        15 1.7742 43377304 completion_criteria_activity->review( ) ..\completion_criteria.php:227
        16 1.7868 43414368 completion_info->get_data( ) ..\completion_criteria_activity.php:139
        Show
        Evan Irving-Pease added a comment - Hi Sam, thanks for the quick turnaround on this but I'm not convinced that suppressing the warning message on the delete action is going to solve this problem. To clarify the PHP notices that I get, these are not caused by the course itself, but rather the completionstatus block that is attached to the course. It would appear that the avtivity completion criteria expects the CM to still exist. Here's the full stack trace: # Time Memory Function Location 1 0.0033 476432 {main} ( ) ..\view.php:0 2 1.2841 24325864 bootstrap_renderer->header( ) ..\view.php:196 3 1.2841 24326016 bootstrap_renderer->__call( ) ..\setuplib.php:0 4 1.2934 24424768 call_user_func_array ( ) ..\setuplib.php:1279 5 1.2934 24424904 core_renderer->header( ) ..\setuplib.php:0 6 1.3303 25061056 core_renderer->render_page_layout( ) ..\outputrenderers.php:612 7 1.3311 25142168 include( 'theme\<themename>\layout\general.php' ) ..\outputrenderers.php:654 8 1.7296 43198776 block_manager->region_has_content( ) ..\general.php:15 9 1.7296 43198776 block_manager->ensure_content_created( ) ..\blocklib.php:349 10 1.7296 43198896 block_manager->create_block_contents( ) ..\blocklib.php:972 11 1.7436 43235416 block_base->get_content_for_output( ) ..\blocklib.php:920 12 1.7436 43236608 block_base->formatted_contents( ) ..\moodleblock.class.php:232 13 1.7436 43236608 block_completionstatus->get_content( ) ..\moodleblock.class.php:280 14 1.7742 43377272 completion_criteria->is_pending( ) ..\block_completionstatus.php:116 15 1.7742 43377304 completion_criteria_activity->review( ) ..\completion_criteria.php:227 16 1.7868 43414368 completion_info->get_data( ) ..\completion_criteria_activity.php:139
        Hide
        Evan Irving-Pease added a comment -

        With the actual errors being...

        Notice: Trying to get property of non-object in \lib\completionlib.php on line 898
        Notice: Trying to get property of non-object in \lib\completionlib.php on line 903
        Notice: Trying to get property of non-object in \lib\completionlib.php on line 912

        It's also worth mentioning that this only happens if you are logged in as the user who had achieved the completion record.

        Show
        Evan Irving-Pease added a comment - With the actual errors being... Notice: Trying to get property of non-object in \lib\completionlib.php on line 898 Notice: Trying to get property of non-object in \lib\completionlib.php on line 903 Notice: Trying to get property of non-object in \lib\completionlib.php on line 912 It's also worth mentioning that this only happens if you are logged in as the user who had achieved the completion record.
        Hide
        Sam Marshall added a comment -

        Evan: Sorry, but actually, that's a separate bug. Would you be able to copy/paste it into a new issue please? Use the 'Course completion' component instead of 'activity completion'.

        The debug warning mentioned (ie the first trace in the original report) is my bug (it's a problem with activity completion). The fix I've done to suppress the warning is, I think, correct, so it should go ahead, so we need to use this bug number for that.

        The error you're seeing is caused by course completion (which is a different part of the system that I don't know much about). That error won't occur unless you set up course completion in addition to activity completion. It is probably unrelated to the activity completion issue. That's why I didn't notice it when reproducing the problem, as I hadn't set up course completion. (Actually I don't know how to...)

        Show
        Sam Marshall added a comment - Evan: Sorry, but actually, that's a separate bug. Would you be able to copy/paste it into a new issue please? Use the 'Course completion' component instead of 'activity completion'. The debug warning mentioned (ie the first trace in the original report) is my bug (it's a problem with activity completion). The fix I've done to suppress the warning is, I think, correct, so it should go ahead, so we need to use this bug number for that. The error you're seeing is caused by course completion (which is a different part of the system that I don't know much about). That error won't occur unless you set up course completion in addition to activity completion. It is probably unrelated to the activity completion issue. That's why I didn't notice it when reproducing the problem, as I hadn't set up course completion. (Actually I don't know how to...)
        Hide
        Eloy Lafuente (stronk7) added a comment -

        Integrated, thanks!

        I've backported this also to 20_STABLE by cherry-pickingig.

        Show
        Eloy Lafuente (stronk7) added a comment - Integrated, thanks! I've backported this also to 20_STABLE by cherry-pickingig.
        Hide
        Rajesh Taneja added a comment -

        Works Great.
        Thanks for fixing this Sam

        Show
        Rajesh Taneja added a comment - Works Great. Thanks for fixing this Sam
        Hide
        Eloy Lafuente (stronk7) added a comment -

        Closing, this is now part of Moodle. Big thanks!

        Show
        Eloy Lafuente (stronk7) added a comment - Closing, this is now part of Moodle. Big thanks!

          People

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

            Dates

            • Created:
              Updated:
              Resolved: