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

Left behind mod_assignment grades cause upgrade error

XMLWordPrintable

    • MOODLE_311_STABLE, MOODLE_39_STABLE, MOODLE_400_STABLE, MOODLE_401_STABLE, MOODLE_402_STABLE
    • MOODLE_311_STABLE, MOODLE_39_STABLE, MOODLE_400_STABLE, MOODLE_401_STABLE
    • MDL-77927-401
    • MDL-77927-master
    • Hide
      Original issue test
      1. Repeat the tests in MDL-72350 and confirm that everything is still passing.

      Testing

      1. Create a new 4.1 instance and install it
      2. Make sure you turn on the debugging
      3. Insert invalid records into grade_items, grade_items and grade_items_history tables by running the following SQL

        INSERT INTO mdl_grade_items(id, itemtype, itemmodule) VALUES(101, 'mod', 'assignment');

        The itemid exists in grade_items

        INSERT INTO mdl_grade_grades(itemid, userid) VALUES(101, 101);

        The itemid does not exists in grade_items

        INSERT INTO mdl_grade_grades(itemid, userid) VALUES(111, 101);

        INSERT INTO mdl_grade_items_history(oldid, itemtype, itemmodule) VALUES(101, 'mod', 'assignment');

      4. Upgrade to 4.2 by checking out master branch
      5. Apply the patch
      6. Follow the upgrade process
      7. Verify that you don't see any warning or exception like the following screenshoot
      8. Verify that you don't see any records of mod_assignment in grade_items by running the following SQL

        SELECT * FROM mdl_grade_items WHERE itemtype = 'mod' AND itemmodule = 'assignment';

      9. Verify that you don't see any records of mod_assignment in grade_items_history by running the following SQL

        SELECT * FROM mdl_grade_items_history WHERE itemtype = 'mod' AND itemmodule = 'assignment';

      10. Verify that you don't see grade_grades record with itemid of "101" and orphaned grade items (itemid="111") from other components are not touched by the upgrade process by running the following SQL

        SELECT * FROM mdl_grade_grades WHERE itemid = 101 OR itemid = 111;

      Testing for 3rd party mod_assignment plugins:

      1. Install a fresh 4.1 instance
      2. Install a mod_assignment plugin e.g. assignment_uploadpdf
      3. Put the plugin files in mod/assignment/type/uploadpdf
      4. Check out the master branch and apply the patch
      5. Confirm that an "Assignment 2.2 subplugins present" error is shown on the environment check and that upgrade cannot continue.
      6. Remove the mod/assignment folder.
      7. Reload the page.
      8. Confirm that upgrade can proceed.

      Testing stable branches (39, 311 and 400).

      1. Install a MOODLE_XXX_STABLE site.
      2. Go to Admin -> Server -> Environment.
      3. Verify that there aren't errors related to Assignment 2.2 is in use.
      4. Install a mod_assignment plugin e.g. assignment_uploadpdf
      5. Put the plugin files in mod/assignment/type/uploadpdf
      6. Follow upgrade process
      7. Go to Site admin/Server/Environment
      8. In the "Moodle version" drop down, select "Moodle 4.2 and upwards".
      9. Verify that you see an error of Assignment 2.2 is in use
      10. If there are other versions in the "Moodle version" drop down... verify that only "4.2 and upwards" shows the error.
      11. Repeat all the steps above for the other branches.
      Show
      Original issue test Repeat the tests in MDL-72350 and confirm that everything is still passing. Testing Create a new 4.1 instance and install it Make sure you turn on the debugging Insert invalid records into grade_items, grade_items and grade_items_history tables by running the following SQL INSERT INTO mdl_grade_items(id, itemtype, itemmodule) VALUES (101, 'mod' , 'assignment' ); The itemid exists in grade_items INSERT INTO mdl_grade_grades(itemid, userid) VALUES (101, 101); The itemid does not exists in grade_items INSERT INTO mdl_grade_grades(itemid, userid) VALUES (111, 101); INSERT INTO mdl_grade_items_history(oldid, itemtype, itemmodule) VALUES (101, 'mod' , 'assignment' ); Upgrade to 4.2 by checking out master branch Apply the patch Follow the upgrade process Verify that you don't see any warning or exception like the following screenshoot Verify that you don't see any records of mod_assignment in grade_items by running the following SQL SELECT * FROM mdl_grade_items WHERE itemtype = 'mod' AND itemmodule = 'assignment' ; Verify that you don't see any records of mod_assignment in grade_items_history by running the following SQL SELECT * FROM mdl_grade_items_history WHERE itemtype = 'mod' AND itemmodule = 'assignment' ; Verify that you don't see grade_grades record with itemid of "101" and orphaned grade items (itemid="111") from other components are not touched by the upgrade process by running the following SQL SELECT * FROM mdl_grade_grades WHERE itemid = 101 OR itemid = 111; Testing for 3rd party mod_assignment plugins: Install a fresh 4.1 instance Install a mod_assignment plugin e.g. assignment_uploadpdf Put the plugin files in mod/assignment/type/uploadpdf Check out the master branch and apply the patch Confirm that an "Assignment 2.2 subplugins present" error is shown on the environment check and that upgrade cannot continue. Remove the mod/assignment folder. Reload the page. Confirm that upgrade can proceed. Testing stable branches (39, 311 and 400). Install a MOODLE_XXX_STABLE site. Go to Admin -> Server -> Environment. Verify that there aren't errors related to Assignment 2.2 is in use . Install a mod_assignment plugin e.g. assignment_uploadpdf Put the plugin files in mod/assignment/type/uploadpdf Follow upgrade process Go to Site admin/Server/Environment In the "Moodle version" drop down, select "Moodle 4.2 and upwards". Verify that you see an error of Assignment 2.2 is in use If there are other versions in the "Moodle version" drop down... verify that only "4.2 and upwards" shows the error. Repeat all the steps above for the other branches.
    • 2
    • Team Hedgehog 2023 Sprint 1.4
    • Small

      We found while doing a test Moodle 4.2 beta upgrade that our database has leftover assignment grade_items and grade_grades, even though we converted to assign long long long ago, and in fact, we have no entries in the mdl_assignment table (this also means that the check_mod_assignment environment check passes just fine). Ultimately this results in this error:

      -->assignment
      !!! Cannot be executed during upgrade !!!
      !! 
      Error code: cannotexecduringupgrade !!
      !! Stack trace: * line 1464 of /lib/setuplib.php: moodle_exception thrown
      * line 2543 of /lib/modinfolib.php: call to upgrade_ensure_not_running()
      * line 2578 of /lib/grade/grade_item.php: call to get_fast_modinfo()
      * line 1253 of /lib/grade/grade_grade.php: call to 
      grade_item->get_context()
      * line 1101 of /lib/grade/grade_grade.php: call to 
      grade_grade->get_context()
      * line 304 of /lib/grade/grade_object.php: call to 
      grade_grade->delete_feedback_files()
      * line 1122 of /lib/grade/grade_grade.php: call to 
      grade_object->delete()
      * line 448 of /lib/grade/grade_item.php: call to grade_grade->delete()
      * line 419 of /lib/grade/grade_item.php: call to 
      grade_item->delete_all_grades()
      * line 1543 of /lib/gradelib.php: call to grade_item->delete()
      * line 262 of /lib/classes/plugininfo/mod.php: call to 
      grade_uninstalled_module()
      * line 203 of /lib/adminlib.php: call to 
      core\plugininfo\mod->uninstall_cleanup()
      * line 3201 of /lib/db/upgrade.php: call to uninstall_plugin()
      * line 1905 of /lib/upgradelib.php: call to xmldb_main_upgrade()
      * line 268 of /admin/cli/upgrade.php: call to upgrade_core()
       !!
      
      

       

      While this is obviously some weird edge case, I'm pretty sure they upgrade should be more resilient to this issue - because this site this was testing on is nothing special, other than it a large site that has been in use a long long time (but kept very updated).

      Steps to reproduce

      1. Create a new 4.1 instance and install it
      2. Make sure you turn on the debugging
      3. Create a course and an assignment in the new created course
      4. Grade the assignment
      5. Add: grade_update('mod/assignment',$course->id, 'mod', 'assignment', 10, 0, 80); to the end of mod/assign/view.php file to generate invalid data.
      6. Visit the graded assignment page
      7. Upgrade to 4.2 by checking out master branch
      8. Follow the upgrade process
      9. Verify that you see a warning or exception like the following screenshoot

        1. successful_upgrade.png
          successful_upgrade.png
          96 kB
        2. successful_upgrade_2.png
          successful_upgrade_2.png
          95 kB
        3. stable_envcheck.png
          stable_envcheck.png
          144 kB
        4. plugin_files.png
          plugin_files.png
          320 kB
        5. image.png
          image.png
          288 kB
        6. error_shown_with_plugin.png
          error_shown_with_plugin.png
          35 kB
        7. error_gone_assignment_folder_removed.png
          error_gone_assignment_folder_removed.png
          47 kB
        8. db_tables_before_upgrade.png
          db_tables_before_upgrade.png
          442 kB
        9. db_tables_after_upgrade.png
          db_tables_after_upgrade.png
          423 kB

            stevani.andolo@moodle.com Stevani Andolo
            emerrill Eric Merrill
            Safat Shahin Safat Shahin
            Jun Pataleta Jun Pataleta
            David Woloszyn David Woloszyn
            Votes:
            1 Vote for this issue
            Watchers:
            17 Start watching this issue

              Created:
              Updated:
              Resolved:

                Estimated:
                Original Estimate - 0 minutes
                0m
                Remaining:
                Remaining Estimate - 0 minutes
                0m
                Logged:
                Time Spent - 1 week, 7 hours, 6 minutes
                1w 7h 6m

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