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

Assignment ID number field changing when student submits assignment


    • Type: Bug
    • Status: Closed
    • Priority: Critical
    • Resolution: Fixed
    • Affects Version/s: 1.9.7
    • Fix Version/s: 1.9.9
    • Component/s: Assignment (2.2)
    • Labels:
    • Environment:
    • Database:
    • Affected Branches:
    • Fixed Branches:


      I've noticed a bug where if you set an ID in the Common Module settings portion of an advanced file upload assignment's settings page, the ID of the corresponding gradebook item gets overwritten with a number when a student submits an assignment.

      For example, say you made an advanced upload assignment and set the ID number field to "asdf". If you go to the gradebook (categories and Items - simple view) and click edit on the grade item for the assignment, you can see that the ID will be "asdf" as expected. Next, you then log in as a student and submit a file for marking on the assignment. Then, log back in as a teacher and go back to the gradebook (categories and items - simple view). if you click edit on the assignment grade item now, you will see that the ID field has been replaced by a number. This also affects XML exports from the gradebook too, as the grade items for the affected assignment will have the wrong ID in the xml export. Interestingly, if you open the assignment's settings page and save it again, the ID in the gradebook will be reset to the correct value.

      I did some digging and found that the new ID number that was showing up in the gradebook comes from the mdl_course_modules table. Instead of the grade item having mdl_course_modules.idnumber (which holds the value that you entered on the assignment settings page), it has mdl_course_modules.id (which is the auto-generated course module id number).

      Looking through the code, I found in mod/assignment/lib.php at line 74,in the assignment class constructor, you have:

      $this->assignment->cmidnumber = $this->cm->id; // compatibility with modedit assignment obj
      $this->assignment->courseid = $this->course->id; // compatibility with modedit assignment obj

      The fix that I have tried so far is to change this to:

      $this->assignment->cmidnumber = $this->cm->idnumber; // compatibility with modedit assignment obj
      $this->assignment->courseid = $this->course->id; // compatibility with modedit assignment obj

      This corrects the problem, but I haven't tested it thoroughly as of yet.

        Gliffy Diagrams


            Issue Links



                • Votes:
                  0 Vote for this issue
                  2 Start watching this issue


                  • Created:
                    Fix Release Date: