Moodle
  1. Moodle
  2. MDL-33877

"Found more than one record in fetch() !" exception when editing settings on an upgraded assignment

    Details

    • Testing Instructions:
      Hide
      1. On a clean moodle installation create 1 instance of the old assignment module and 1 instance of the new assignment module. (Must be clean so the database ids will collide)
      2. Use the assignment upgrade tool to upgrade the old assignment
      3. Edit the settings for the upgraded assignment and click save
      4. Verify that the settings are saved and you do not receive an error: "Found more than one record in fetch() !"
      Show
      On a clean moodle installation create 1 instance of the old assignment module and 1 instance of the new assignment module. (Must be clean so the database ids will collide) Use the assignment upgrade tool to upgrade the old assignment Edit the settings for the upgraded assignment and click save Verify that the settings are saved and you do not receive an error: "Found more than one record in fetch() !"
    • Affected Branches:
      MOODLE_23_STABLE
    • Fixed Branches:
      MOODLE_23_STABLE
    • Pull Master Branch:
    • Rank:
      41979

      Description

      When an assignment has been upgraded from 2.2 to 2.3, in certain circumstances it can become broken. Whenever the user submits a change to any setting; Moodle throws an exception. The exception is:

      Found more than one record in fetch() !

      More information about this error
      Debug info:
      Error code: morethanonerecordinfetch
      Stack trace:

      line 467 of /lib/setuplib.php: moodle_exception thrown
      line 163 of /lib/grade/grade_object.php: call to print_error()
      line 326 of /lib/grade/grade_item.php: call to grade_object::fetch_helper()
      line 291 of /course/moodleform_mod.php: call to grade_item::fetch()
      line 120 of /mod/assign/mod_form.php: call to moodleform_mod->validation()
      line 523 of /lib/formslib.php: call to mod_assign_mod_form->validation()
      line 472 of /lib/formslib.php: call to moodleform->validate_defined_fields()
      line 569 of /lib/formslib.php: call to moodleform->is_validated()
      line 269 of /course/modedit.php: call to moodleform->get_data()

      This is very difficult to recreate as it is more of a problem on the qa.moodle.net and Mount Orange School demo site.

      To recreate:
      Method 1:
      Test Pre-requisites:

      • Use the attached backup file of the Moodle Features demo course.

      Test steps:

      1. Restore the course and access any of the assignments under the Label OLD 2.2 Assignments. These are 2.2 assignments converted to 2.3 on the MoodleQA site.
      2. Navigate to Assignment settings and change any setting (I used grading method, setting it to marking guide).
      3. Click Save and display.

      Expected result:

      • Moodle displays the correct page (in my case marking guide).

      Actual result:

      • Moodle displays the aforementioned exception and the changes are not saved.

      Method 2 - this only works on my local Moodle with Advanced uploading of files:
      Test steps:

      1. Create an Advanced uploading of files 2.2 assignment subtype in any course.
      2. Upgrade the assignment to 2.3.
      3. Navigate to Assignment settings and change any setting (I used grading method, setting it to marking guide).
      4. Click Save and display.

      Expected result:

      • Moodle displays the correct page (in my case marking guide).

      Actual result:

      • Moodle displays the aforementioned exception and the changes are not saved.2
      1. mdl_grade_items.csv
        4 kB
        Tim Barker

        Issue Links

          Activity

          Hide
          Damyon Wiese added a comment -

          This is caused by this bug: MDL-33464 which has been fixed. However assignments that were upgraded before this patch would still be broken.

          If this were the only bug - I would recommend some SQL to remove the duplicate grade_items from the gradebook - however there is a more critical bug (MDL-33793) that has been fixed which could result in silent data loss / obscure bugs and so my recommendation is to restore a backup from before the upgrade of the assignments and re-upgrade them with the latest code.

          Show
          Damyon Wiese added a comment - This is caused by this bug: MDL-33464 which has been fixed. However assignments that were upgraded before this patch would still be broken. If this were the only bug - I would recommend some SQL to remove the duplicate grade_items from the gradebook - however there is a more critical bug ( MDL-33793 ) that has been fixed which could result in silent data loss / obscure bugs and so my recommendation is to restore a backup from before the upgrade of the assignments and re-upgrade them with the latest code.
          Hide
          Rajesh Taneja added a comment -

          Thanks Damyon,

          I can't reproduce this issue, although Tim just restored a new course and he can still reproduce this issue. In his case Assignments were upgraded after the patch (at time of restoring), so he should not face problem in newly restored course assignments. Should he ?

          Show
          Rajesh Taneja added a comment - Thanks Damyon, I can't reproduce this issue, although Tim just restored a new course and he can still reproduce this issue. In his case Assignments were upgraded after the patch (at time of restoring), so he should not face problem in newly restored course assignments. Should he ?
          Hide
          Rajesh Taneja added a comment -

          In attached backup, grades.xml (activities/assign_83/grades.xml) have two records and they get restored in database, corrupting grades_item table.
          So I propose:

          1. adding constrain on grades_item table for unique itemtype-itemmodule-iteminstance-itemnumber-courseid
          2. Add check while backing and restoring to make sure we don't generate bad backup files.

          Alternately for MoodleQA site we can run sql to delete grade records for invalid instanceid

          Show
          Rajesh Taneja added a comment - In attached backup, grades.xml (activities/assign_83/grades.xml) have two records and they get restored in database, corrupting grades_item table. So I propose: adding constrain on grades_item table for unique itemtype-itemmodule-iteminstance-itemnumber-courseid Add check while backing and restoring to make sure we don't generate bad backup files. Alternately for MoodleQA site we can run sql to delete grade records for invalid instanceid
          Hide
          Andrew Davis added a comment -
          Show
          Andrew Davis added a comment - It sounds like others are still experiencing problems with the upgrade process http://tracker.moodle.org/browse/MDL-33464?focusedCommentId=163939&page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#comment-163939
          Hide
          Dan Poltawski added a comment -

          The big question here which we need to establish the answer to is if this is an issue remaining in the upgrade or is a remenant from the two existing issues which would cause this issue.

          Show
          Dan Poltawski added a comment - The big question here which we need to establish the answer to is if this is an issue remaining in the upgrade or is a remenant from the two existing issues which would cause this issue.
          Hide
          Rajesh Taneja added a comment - - edited

          It seems like, we are updating 2.3 assignment instanceid in grades_item and that is causing problem and only problem is with batch upgrade.

          Show
          Rajesh Taneja added a comment - - edited It seems like, we are updating 2.3 assignment instanceid in grades_item and that is causing problem and only problem is with batch upgrade.
          Hide
          Tim Barker added a comment -

          We finally got to the bottom of what is happening here.

          Test steps:

          1. Restore the enclosed backup file: backup-with_2.2_assignments.mbz, to a new course.
          2. Run the upgrade tool on the 2.2 assignments.
          3. select * from mdl_grade_items and you will see that the instance id's of the records with the id's 2 to 5 are duplicated in the records with id's 6 to 9.

          Also see the enclosed csv file from the table in my DB.

          Show
          Tim Barker added a comment - We finally got to the bottom of what is happening here. Test steps: Restore the enclosed backup file: backup-with_2.2_assignments.mbz, to a new course. Run the upgrade tool on the 2.2 assignments. select * from mdl_grade_items and you will see that the instance id's of the records with the id's 2 to 5 are duplicated in the records with id's 6 to 9. Also see the enclosed csv file from the table in my DB.
          Hide
          Damyon Wiese added a comment -
          Show
          Damyon Wiese added a comment - A patch is here: (Still testing this myself) https://github.com/netspotau/moodle-mod_assign/commit/1f417de84a9de7448fa1b55385462e79e67a1791
          Hide
          Rajesh Taneja added a comment -

          Thanks Damyon,

          Assigning this bug to you, as you know more about this

          Show
          Rajesh Taneja added a comment - Thanks Damyon, Assigning this bug to you, as you know more about this
          Hide
          Damyon Wiese added a comment -

          I have verified that the testing instructions reproduce the bug and that the patch fixes the issue.

          Show
          Damyon Wiese added a comment - I have verified that the testing instructions reproduce the bug and that the patch fixes the issue.
          Hide
          Dan Poltawski added a comment -

          Hi Damyon,

          Could you explain the fix, i'm not understnading the difference between the set_field/update_record calls right now!

          Show
          Dan Poltawski added a comment - Hi Damyon, Could you explain the fix, i'm not understnading the difference between the set_field/update_record calls right now!
          Hide
          Damyon Wiese added a comment -

          No problem,

          Consider these lines:

          224: $DB->set_field('grade_items', 'itemmodule', 'assign', array('iteminstance'=>$oldassignment->id, 'itemmodule'=>'assignment'));
          225: $DB->set_field('grade_items', 'iteminstance', $newassignment->get_instance()->id, array('iteminstance'=>$oldassignment->id, 'itemmodule'=>'assign'));
          

          If - before the upgrade the grade_items table contains 2 records:

          id itemmodule iteminstance
          100 assign 100
          101 assignment 100

          And old id is 100 and new id is 101

          After line 224 we will have:

          id itemmodule iteminstance
          100 assign 100
          101 assign 100

          After line 225 we will have:

          id itemmodule iteminstance
          100 assign 101
          101 assign 101

          So the problem is when we have an old and a new assignment with the same id before the upgrade - the existing new assignment will be clobbered. This same logic affects the course completion items.

          The fix gets the id of the record to change and then calls update on that record so it will only update the one record and set both columns at the same time.

          Show
          Damyon Wiese added a comment - No problem, Consider these lines: 224: $DB->set_field('grade_items', 'itemmodule', 'assign', array('iteminstance'=>$oldassignment->id, 'itemmodule'=>'assignment')); 225: $DB->set_field('grade_items', 'iteminstance', $newassignment->get_instance()->id, array('iteminstance'=>$oldassignment->id, 'itemmodule'=>'assign')); If - before the upgrade the grade_items table contains 2 records: id itemmodule iteminstance 100 assign 100 101 assignment 100 And old id is 100 and new id is 101 After line 224 we will have: id itemmodule iteminstance 100 assign 100 101 assign 100 After line 225 we will have: id itemmodule iteminstance 100 assign 101 101 assign 101 So the problem is when we have an old and a new assignment with the same id before the upgrade - the existing new assignment will be clobbered. This same logic affects the course completion items. The fix gets the id of the record to change and then calls update on that record so it will only update the one record and set both columns at the same time.
          Hide
          Dan Poltawski added a comment -

          Thanks for the explanation.

          Integrated. Lets hope we've finally cracked it

          Thanks Damyon!

          Show
          Dan Poltawski added a comment - Thanks for the explanation. Integrated. Lets hope we've finally cracked it Thanks Damyon!
          Hide
          Jason Fowler added a comment -

          All good Damyon, thanks for fixing this

          Show
          Jason Fowler added a comment - All good Damyon, thanks for fixing this
          Hide
          Eloy Lafuente (stronk7) added a comment -

          And this has been incorporated to all the weekly builds and also, to Moodle 2.3 Release Candidate 1, yay!

          Many, many thanks for your hard work!

          Ciao

          Show
          Eloy Lafuente (stronk7) added a comment - And this has been incorporated to all the weekly builds and also, to Moodle 2.3 Release Candidate 1, yay! Many, many thanks for your hard work! Ciao
          Hide
          Eloy Lafuente (stronk7) added a comment -

          Note this had originally one "mdlqa" label, that has been deleted on close... but there was no MDLQA linked to it, so perhaps there could be something in the QA project pending to be reset related to this.

          Show
          Eloy Lafuente (stronk7) added a comment - Note this had originally one "mdlqa" label, that has been deleted on close... but there was no MDLQA linked to it, so perhaps there could be something in the QA project pending to be reset related to this.
          Hide
          Mary Cooch added a comment -

          I have just experienced this problem once more on the School demo site despite its being upgraded to 2.3 stable. Not sure whether to start a new issue for it?

          Show
          Mary Cooch added a comment - I have just experienced this problem once more on the School demo site despite its being upgraded to 2.3 stable. Not sure whether to start a new issue for it?
          Hide
          Dan Poltawski added a comment -

          Hi Mary,

          Its almost certainly bad data in the school demo site, so it'd be a MDLSITE issue.

          Show
          Dan Poltawski added a comment - Hi Mary, Its almost certainly bad data in the school demo site, so it'd be a MDLSITE issue.
          Hide
          Mary Cooch added a comment -

          Ok I will go and add it there -thanks

          Show
          Mary Cooch added a comment - Ok I will go and add it there -thanks

            People

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

              Dates

              • Created:
                Updated:
                Resolved: