Moodle
  1. Moodle
  2. MDL-31407

Quiz grades are not saved properly when the submitter is not the user taking the quiz.

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Trivial Trivial
    • Resolution: Fixed
    • Affects Version/s: 2.1.4, 2.2.1, 2.3
    • Fix Version/s: 2.1.5, 2.2.2
    • Component/s: Quiz
    • Labels:
      None
    • Testing Instructions:
      Hide

      The main thing is to test there are no regressions.

      1. Create a quiz that allows two attempts.
      2. Preview it as teacher. Verify that there are no errors, particularly when doing submit all and finish.
      3. Attempt the quiz as a student. Verify that there are no errors, particularly when doing submit all and finish. Then verify that the grade is displayed correct on the quiz view.php page and in the gradebook.
      4. Now make a second attempt as a student getting a different (higher) grade. Verify that the grade is updated on view.php and in the gradebook.

      5. If you really want to test this thoroughly, Create a script that submits open quiz attempts belonging to someone other than the logged in user, and then make sure that it works. However, I really don't think that is necessary.

      Show
      The main thing is to test there are no regressions. 1. Create a quiz that allows two attempts. 2. Preview it as teacher. Verify that there are no errors, particularly when doing submit all and finish. 3. Attempt the quiz as a student. Verify that there are no errors, particularly when doing submit all and finish. Then verify that the grade is displayed correct on the quiz view.php page and in the gradebook. 4. Now make a second attempt as a student getting a different (higher) grade. Verify that the grade is updated on view.php and in the gradebook. 5. If you really want to test this thoroughly, Create a script that submits open quiz attempts belonging to someone other than the logged in user, and then make sure that it works. However, I really don't think that is necessary.
    • Difficulty:
      Easy
    • Affected Branches:
      MOODLE_21_STABLE, MOODLE_22_STABLE, MOODLE_23_STABLE
    • Fixed Branches:
      MOODLE_21_STABLE, MOODLE_22_STABLE
    • Pull from Repository:
    • Pull Master Branch:
    • Rank:
      37929

      Description

      Currently, the finish_attempt() function updates the quiz grade for the currently logged in user ($USER) no matter whose quiz attempt is being finished. The cause is the following line:

      quiz_save_best_grade($this->get_quiz());

      As a result, the finished attempt grade is never pushed to the gradebook. It would make more sense for finish_attempt() to update the grade for the user whose quiz attempt is being closed, a la:

      quiz_save_best_grade($this->get_quiz(), $this->attempt->userid);

      As far as I know, this does't currently cause issues in the Moodle core code, because Quiz attempts are always submitted by the owning user. Plugins which use question_usage_by_activity are affected; and this will likely cause issues with MDL-3030, when that comes to fruition.

      1. mdl_31407_typofixed.patch
        0.6 kB
        Kyle Temkin
      2. mdl_31407_typofixed.patch
        0.6 kB
        Kyle Temkin
      3. mdl_31407.patch
        0.6 kB
        Kyle Temkin

        Activity

        Hide
        Tim Hunt added a comment -

        Interesting. You are right that this possibility has not come up before. I am busy over the next few days, but I will try to look at this later this week.

        Show
        Tim Hunt added a comment - Interesting. You are right that this possibility has not come up before. I am busy over the next few days, but I will try to look at this later this week.
        Hide
        Tim Hunt added a comment -

        Obviously, the git history needs to be cleaned up before this can be integrated. I have just done that.

        Show
        Tim Hunt added a comment - Obviously, the git history needs to be cleaned up before this can be integrated. I have just done that.
        Hide
        Tim Hunt added a comment -

        Note, while reviewing this, I took the opportunity to review all uses of global $USER in the quiz, and found several mentions that could be eliminated, so I eliminated them in a second commit.

        Show
        Tim Hunt added a comment - Note, while reviewing this, I took the opportunity to review all uses of global $USER in the quiz, and found several mentions that could be eliminated, so I eliminated them in a second commit.
        Hide
        Eloy Lafuente (stronk7) added a comment -

        The main moodle.git repository has just been updated with latest weekly modifications. You may wish to rebase your PULL branches to simplify history and avoid any possible merge conflicts. This would also make integrator's life easier next week.

        TIA and ciao

        Show
        Eloy Lafuente (stronk7) added a comment - The main moodle.git repository has just been updated with latest weekly modifications. You may wish to rebase your PULL branches to simplify history and avoid any possible merge conflicts. This would also make integrator's life easier next week. TIA and ciao
        Hide
        Aparup Banerjee added a comment -

        Thanks for the fix and the spontaneous clean up!
        fix is good and clean up has been verified, this is not integrated into master, 22 and 21.

        Show
        Aparup Banerjee added a comment - Thanks for the fix and the spontaneous clean up! fix is good and clean up has been verified, this is not integrated into master, 22 and 21.
        Hide
        Ankit Agarwal added a comment -

        This is working great!
        Thanks!

        Show
        Ankit Agarwal added a comment - This is working great! Thanks!
        Hide
        Tim Hunt added a comment -

        I'm glad I am not the only person in the world who gets not and now confused when typing. Just to clarify Aparup's comment: http://tracker.moodle.org/browse/MDL-31407?focusedCommentId=143387&page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#comment-143387 I am sure he means 'now'.

        Show
        Tim Hunt added a comment - I'm glad I am not the only person in the world who gets not and now confused when typing. Just to clarify Aparup's comment: http://tracker.moodle.org/browse/MDL-31407?focusedCommentId=143387&page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#comment-143387 I am sure he means 'now'.
        Hide
        Aparup Banerjee added a comment -

        LOL yes Tim is right! it is NOW (awhile ago actually) integrated. Thank you Tim! .

        Show
        Aparup Banerjee added a comment - LOL yes Tim is right! it is NOW (awhile ago actually) integrated. Thank you Tim! .
        Hide
        Eloy Lafuente (stronk7) added a comment -

        A bit later this week, but finally your changes have been accepted and are now available in all the upstream git/cvs servers.

        Many thanks & ciao

        Show
        Eloy Lafuente (stronk7) added a comment - A bit later this week, but finally your changes have been accepted and are now available in all the upstream git/cvs servers. Many thanks & ciao

          People

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

            Dates

            • Created:
              Updated:
              Resolved: