Moodle
  1. Moodle
  2. MDL-29270

Question's default grade is not correctly restored from 1.9 backups

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Critical Critical
    • Resolution: Fixed
    • Affects Version/s: 2.1.1, 2.2
    • Fix Version/s: 2.1.2
    • Component/s: Backup, Questions
    • Labels:
    • Environment:
      2.1.1+, Build: 20110831, PHP Version 5.3.6, MySQL 5.1.57.
    • Database:
      Any
    • Testing Instructions:
      Hide

      Note: the patch already tested by Jean-Michel Vedrine

      In Moodle 2.1, restore a 1.9 backup with description questions and also various question types having default grade value different from 1. Verify that in the restored course description questions still have 0 as default mark and that other questions default mark are not changed to 1.

      Show
      Note: the patch already tested by Jean-Michel Vedrine In Moodle 2.1, restore a 1.9 backup with description questions and also various question types having default grade value different from 1. Verify that in the restored course description questions still have 0 as default mark and that other questions default mark are not changed to 1.
    • Workaround:
      Hide

      In the gradebook, I can create a multiplier to fix the grade. In this case, the multiplier is 32/27.

      Show
      In the gradebook, I can create a multiplier to fix the grade. In this case, the multiplier is 32/27.
    • Affected Branches:
      MOODLE_21_STABLE, MOODLE_22_STABLE
    • Fixed Branches:
      MOODLE_21_STABLE
    • Pull from Repository:
    • Pull Master Branch:
      MDL-29270-question-grade
    • Rank:
      18976

      Description

      I designed a quiz that also included some "description" items. The quiz had 27 questions (see Exam1 graphic). Each question was worth one point. Overall, the quiz was worth 100 points.

      In the attachment, you can see that there were 27 questions, and 9 "description" items for a total of 36 quiz items. I am not sure where Moodle is getting the "32". Somehow, it sees that every question was correct, and calculates 27/32 * 100, which is 84.4%

      I saw this problem last week on another quiz, but didn't have time to report it. Now it is an obvious problem in the Moodle grading system.

      1. Exam1.jpg
        151 kB
      2. Exam2.jpg
        157 kB
      3. Exam3.jpg
        94 kB

        Activity

        Hide
        Rick Jerz added a comment - - edited

        I am not sure how priorities are assigned.

        This problem I see is tagged as "minor". Gradebook errors, to me, should probably have a little higher priority.

        Show
        Rick Jerz added a comment - - edited I am not sure how priorities are assigned. This problem I see is tagged as "minor". Gradebook errors, to me, should probably have a little higher priority.
        Hide
        Chris Collman added a comment - - edited

        I agree with the priority, the default is "minor" but I think you have the power to up it and for the assignee to change it. You should be able to change the priority by clicking on the Edit tab. You should see priority with "Minor" in the box. Use the pull down

        I have not noticed this problem. But I do not use the info (description) pages except on my sample exams. This semester I was doing lots of screen shots and test students using the sample. We have opened 20 or so quizzes in 2.1 and 10 to 40 students taking each, Seemed to be scoring correctly but again, we only use MC questions and KISS.

        Show
        Chris Collman added a comment - - edited I agree with the priority, the default is "minor" but I think you have the power to up it and for the assignee to change it. You should be able to change the priority by clicking on the Edit tab. You should see priority with "Minor" in the box. Use the pull down I have not noticed this problem. But I do not use the info (description) pages except on my sample exams. This semester I was doing lots of screen shots and test students using the sample. We have opened 20 or so quizzes in 2.1 and 10 to 40 students taking each, Seemed to be scoring correctly but again, we only use MC questions and KISS.
        Hide
        Rick Jerz added a comment -

        I somehow don't see the ability to change its priority.

        I use description items to separate sections of my exams, and also to provide some information for the next set of questions.

        I tried creating a simple exam, starting with a Description item, followed by a Multiple Choice question, followed by a Description item. The error occurs. I thought that the problem might have something to do with two Description items back-to-back, but it doesn't. My picture Exam1.jpg shows a count error of "5" (32-27). So it may have something to do with groups of Description items, since Exam1.jpg shows 5 groups of "i's".

        Show
        Rick Jerz added a comment - I somehow don't see the ability to change its priority. I use description items to separate sections of my exams, and also to provide some information for the next set of questions. I tried creating a simple exam, starting with a Description item, followed by a Multiple Choice question, followed by a Description item. The error occurs. I thought that the problem might have something to do with two Description items back-to-back, but it doesn't. My picture Exam1.jpg shows a count error of "5" (32-27). So it may have something to do with groups of Description items, since Exam1.jpg shows 5 groups of "i's".
        Hide
        Jean-Michel Vedrine added a comment -

        I am not sure about the component : maybe it's not a gradebook or quiz problem, but a question problem

        Show
        Jean-Michel Vedrine added a comment - I am not sure about the component : maybe it's not a gradebook or quiz problem, but a question problem
        Hide
        Joseph Rézeau added a comment -

        I agree with Jean-Michel,
        From the detailed description of the problem on the Quiz forum, it appears that this is a problem with a problematic Description question.
        We are waiting for the OP (Rick) to conduct more tests and report.

        Show
        Joseph Rézeau added a comment - I agree with Jean-Michel, From the detailed description of the problem on the Quiz forum, it appears that this is a problem with a problematic Description question. We are waiting for the OP (Rick) to conduct more tests and report.
        Hide
        Rick Jerz added a comment -

        I did a bunch of experimenting. I could not produce the error if I created new Description questions and then added them to the Quiz. Then I even tried making some description item in Moodle 1.9.12, exporting them, then importing them to see if this could give me some insight. It didn't, they worked fine. The I exported the questions that were causing this problem, imported them into my experimental Moodle 2.1.1 to see what would happen, and the problem did not present itself.

        Well, this leaves me puzzled. Here's what I can tell you.

        It was about 1 1/2 months ago that I began with my production version of Moodle 2.1. To get started quickly, I exported my course from 1.9.12, then imported it to Moodle 2.1. Of course, all the the quiz questions came into Moodle 2.1. It appears that it is the Description questions from this initial import that are giving me problems right now. Puzzling, isn't it?

        I will be creating a new quiz, a real one for my students, in about a week. I think what I will do is to create it just as I have done so in the past, but to carefully watch how Moodle increments the question points. If I see the problem occur again, I will create a brand new Description question and try using it. My guess (at this point in time) is that the brand-new item should work.

        I can report back on this item in about a week.

        Show
        Rick Jerz added a comment - I did a bunch of experimenting. I could not produce the error if I created new Description questions and then added them to the Quiz. Then I even tried making some description item in Moodle 1.9.12, exporting them, then importing them to see if this could give me some insight. It didn't, they worked fine. The I exported the questions that were causing this problem, imported them into my experimental Moodle 2.1.1 to see what would happen, and the problem did not present itself. Well, this leaves me puzzled. Here's what I can tell you. It was about 1 1/2 months ago that I began with my production version of Moodle 2.1. To get started quickly, I exported my course from 1.9.12, then imported it to Moodle 2.1. Of course, all the the quiz questions came into Moodle 2.1. It appears that it is the Description questions from this initial import that are giving me problems right now. Puzzling, isn't it? I will be creating a new quiz, a real one for my students, in about a week. I think what I will do is to create it just as I have done so in the past, but to carefully watch how Moodle increments the question points. If I see the problem occur again, I will create a brand new Description question and try using it. My guess (at this point in time) is that the brand-new item should work. I can report back on this item in about a week.
        Hide
        Rick Jerz added a comment -

        I discovered a few more interesting things. I added my comments to http://moodle.org/mod/forum/discuss.php?d=185206.

        See if this helps.

        Show
        Rick Jerz added a comment - I discovered a few more interesting things. I added my comments to http://moodle.org/mod/forum/discuss.php?d=185206 . See if this helps.
        Hide
        Jean-Michel Vedrine added a comment -

        It's in fact a problem in the restore of 1.9 backups : to test I made a bachup in Moodle 1.9.x with some description questions and restored it in Moodle 2.1. All the description questions had their defaultmark set to 1.0000000

        Show
        Jean-Michel Vedrine added a comment - It's in fact a problem in the restore of 1.9 backups : to test I made a bachup in Moodle 1.9.x with some description questions and restored it in Moodle 2.1. All the description questions had their defaultmark set to 1.0000000
        Hide
        Jean-Michel Vedrine added a comment -

        Well in fact doing further tests it seems that description is not the only question type affected by this problem. I can reproduce it with shortanswer questions too. It seems that all questions that I backup in Moodle 1.9 and restore in Moodle 2.1 have their defaultmark set to 1 whatever it was previously in Moodle 1.9
        This seems a little more serious because if the problem can easily be corrected for descriptions resetting their defaultmark field to 0, this is not so easy with other questions types.
        Probably this is a problem with the change of name from degaultgrade to defaultmark between 1.9 and 2.1

        Show
        Jean-Michel Vedrine added a comment - Well in fact doing further tests it seems that description is not the only question type affected by this problem. I can reproduce it with shortanswer questions too. It seems that all questions that I backup in Moodle 1.9 and restore in Moodle 2.1 have their defaultmark set to 1 whatever it was previously in Moodle 1.9 This seems a little more serious because if the problem can easily be corrected for descriptions resetting their defaultmark field to 0, this is not so easy with other questions types. Probably this is a problem with the change of name from degaultgrade to defaultmark between 1.9 and 2.1
        Hide
        Jean-Michel Vedrine added a comment -

        The problem seems to be in the code in backup/converter/moodle1/handlerlib.php
        I think the process_question function is missing some lines like :
        // replay the upgrade step 2011060301 - Rename field defaultgrade on table question to defaultmark
        $data['defaultmark'] = $data['defaultgrade'];

        and that the line :
        foreach (array(
        'parent', 'name', 'questiontext', 'questiontextformat',
        'generalfeedback', 'generalfeedbackformat', 'defaultgrade',
        'penalty', 'qtype', 'length', 'stamp', 'version', 'hidden',
        'timecreated', 'timemodified', 'createdby', 'modifiedby'
        ) as $fieldname) {
        should be modified by changing defaultgrade to defaultmark
        I think I will add David as watcher because I think he wrote this code for 2.0.

        Show
        Jean-Michel Vedrine added a comment - The problem seems to be in the code in backup/converter/moodle1/handlerlib.php I think the process_question function is missing some lines like : // replay the upgrade step 2011060301 - Rename field defaultgrade on table question to defaultmark $data ['defaultmark'] = $data ['defaultgrade'] ; and that the line : foreach (array( 'parent', 'name', 'questiontext', 'questiontextformat', 'generalfeedback', 'generalfeedbackformat', 'defaultgrade', 'penalty', 'qtype', 'length', 'stamp', 'version', 'hidden', 'timecreated', 'timemodified', 'createdby', 'modifiedby' ) as $fieldname) { should be modified by changing defaultgrade to defaultmark I think I will add David as watcher because I think he wrote this code for 2.0.
        Hide
        Rick Jerz added a comment - - edited

        Well, I am glad that I might have helped everyone discover this interesting problem. Seems like someone will be making a fix soon, right?

        Show
        Rick Jerz added a comment - - edited Well, I am glad that I might have helped everyone discover this interesting problem. Seems like someone will be making a fix soon, right?
        Hide
        Tim Hunt added a comment -

        Reassigning to moodle.com, since they did the 1.9 restore stuff.

        Show
        Tim Hunt added a comment - Reassigning to moodle.com, since they did the 1.9 restore stuff.
        Hide
        Tim Hunt added a comment -

        I meant to say, congratulations to everyone here. Great job working out what this bug was really about.

        Show
        Tim Hunt added a comment - I meant to say, congratulations to everyone here. Great job working out what this bug was really about.
        Hide
        Jean-Michel Vedrine added a comment - - edited

        Thanks Tim,
        I hope someone from moodle.com can have a look at this ASAP, as for non description questions there is a risk of data loss if the 1.9 website and the backups are no more available.
        For description questions, fortunately this is easy to fix with a simple sql query but not for other question types..

        Show
        Jean-Michel Vedrine added a comment - - edited Thanks Tim, I hope someone from moodle.com can have a look at this ASAP, as for non description questions there is a risk of data loss if the 1.9 website and the backups are no more available. For description questions, fortunately this is easy to fix with a simple sql query but not for other question types..
        Hide
        Tim Hunt added a comment -

        Looking again at Jean-Michel's fix, it looks plausible to me, so I put it in a git commit, and am sending it to David for peer-review.

        Show
        Tim Hunt added a comment - Looking again at Jean-Michel's fix, it looks plausible to me, so I put it in a git commit, and am sending it to David for peer-review.
        Hide
        Jean-Michel Vedrine added a comment -

        Hello Tim and david,
        When I looked at the code I was tinking that the process_question method that needed the added line :
        $data['defaultmark'] = $data['defaultgrade'];
        was the moodle1_question_bank_handler class
        But maybe Tim is right when he add this line to the process_question method of the moodle1_qtype_handler class
        In fact I don't really know.

        Show
        Jean-Michel Vedrine added a comment - Hello Tim and david, When I looked at the code I was tinking that the process_question method that needed the added line : $data ['defaultmark'] = $data ['defaultgrade'] ; was the moodle1_question_bank_handler class But maybe Tim is right when he add this line to the process_question method of the moodle1_qtype_handler class In fact I don't really know.
        Hide
        Tim Hunt added a comment -

        Oh. I did not test my changes. I just tried to apply the changes Jean-Michel suggested. Sorry for getting it on.

        David gets back from holiday on Friday. Hopefully he can sort this out then.

        Show
        Tim Hunt added a comment - Oh. I did not test my changes. I just tried to apply the changes Jean-Michel suggested. Sorry for getting it on. David gets back from holiday on Friday. Hopefully he can sort this out then.
        Hide
        Jean-Michel Vedrine added a comment -

        To David Mudrak :
        Hello David, can you have a look at this issue and see if the fix is good.
        Thanks

        Show
        Jean-Michel Vedrine added a comment - To David Mudrak : Hello David, can you have a look at this issue and see if the fix is good. Thanks
        Hide
        David Mudrak added a comment -

        Yes, I agree with Jean-Michel. From a quick view I would say that the code that actually renames the field should be in moodle1_question_bank_handler::process_question(). Jean-Michel, can you please try and test such approach? If you confirm it solves the issue, I will prepare the new patch for integration. Thanks all for the great work on this!

        For the reference, it seems that the backup code had the same/similar issue which Tim fixed in f3ca24e4187b60e36240055c0475ab568c4ed820 (MDL-20636)

        Show
        David Mudrak added a comment - Yes, I agree with Jean-Michel. From a quick view I would say that the code that actually renames the field should be in moodle1_question_bank_handler::process_question(). Jean-Michel, can you please try and test such approach? If you confirm it solves the issue, I will prepare the new patch for integration. Thanks all for the great work on this! For the reference, it seems that the backup code had the same/similar issue which Tim fixed in f3ca24e4187b60e36240055c0475ab568c4ed820 ( MDL-20636 )
        Hide
        Jean-Michel Vedrine added a comment -

        Hello David,
        Thanks a lot for looking at this issue.
        I can confirm that adding the lines :
        // replay the upgrade step 2011060301 - Rename field defaultgrade on table question to defaultmark
        $data['defaultmark'] = $data['defaultgrade'];
        in moodle1_question_bank_handler::process_question() (I added it after all the others "replay the upgrade step" around line 1223
        and changing :
        foreach (array(
        'parent', 'name', 'questiontext', 'questiontextformat',
        'generalfeedback', 'generalfeedbackformat', 'defaultgrade',
        'penalty', 'qtype', 'length', 'stamp', 'version', 'hidden',
        'timecreated', 'timemodified', 'createdby', 'modifiedby'
        ) as $fieldname) {
        to :
        foreach (array(
        'parent', 'name', 'questiontext', 'questiontextformat',
        'generalfeedback', 'generalfeedbackformat', 'defaultmark',
        'penalty', 'qtype', 'length', 'stamp', 'version', 'hidden',
        'timecreated', 'timemodified', 'createdby', 'modifiedby'
        ) as $fieldname) {
        Seems to solve the problem and have no adverse effect.
        I tested a backup from a fresh Moodle 1.9 course containing various questions types with various default grades and some quizes made of these questions (including some quizes with changed questions' grades) and all is restored OK and I can't detect any problem in the tables.
        You can prepare the patch for integration. Thanks.

        Show
        Jean-Michel Vedrine added a comment - Hello David, Thanks a lot for looking at this issue. I can confirm that adding the lines : // replay the upgrade step 2011060301 - Rename field defaultgrade on table question to defaultmark $data ['defaultmark'] = $data ['defaultgrade'] ; in moodle1_question_bank_handler::process_question() (I added it after all the others "replay the upgrade step" around line 1223 and changing : foreach (array( 'parent', 'name', 'questiontext', 'questiontextformat', 'generalfeedback', 'generalfeedbackformat', 'defaultgrade', 'penalty', 'qtype', 'length', 'stamp', 'version', 'hidden', 'timecreated', 'timemodified', 'createdby', 'modifiedby' ) as $fieldname) { to : foreach (array( 'parent', 'name', 'questiontext', 'questiontextformat', 'generalfeedback', 'generalfeedbackformat', 'defaultmark', 'penalty', 'qtype', 'length', 'stamp', 'version', 'hidden', 'timecreated', 'timemodified', 'createdby', 'modifiedby' ) as $fieldname) { Seems to solve the problem and have no adverse effect. I tested a backup from a fresh Moodle 1.9 course containing various questions types with various default grades and some quizes made of these questions (including some quizes with changed questions' grades) and all is restored OK and I can't detect any problem in the tables. You can prepare the patch for integration. Thanks.
        Hide
        Jean-Michel Vedrine added a comment -

        I just realised Tim has assigned this issue to me ! maybe it would be better if it was assigned to you David.

        Show
        Jean-Michel Vedrine added a comment - I just realised Tim has assigned this issue to me ! maybe it would be better if it was assigned to you David.
        Hide
        Tim Hunt added a comment -

        I assigned it to Jean-Michel when I was reviewing his changes.

        Show
        Tim Hunt added a comment - I assigned it to Jean-Michel when I was reviewing his changes.
        Hide
        David Mudrak added a comment -

        Submitting Jean-Michel's solution for the integration. Thanks a lot!

        Show
        David Mudrak added a comment - Submitting Jean-Michel's solution for the integration. Thanks a lot!
        Hide
        Aparup Banerjee added a comment -

        nice! The patch has been integrated and ready for (additional?) testing.

        Show
        Aparup Banerjee added a comment - nice! The patch has been integrated and ready for (additional?) testing.
        Hide
        Michael de Raadt added a comment -

        Test result: I tested this through the quiz export/import facility and through a course backup/restore. I ran into another issue (MDL-29432), but the default grades did restore with correct default values.

        Show
        Michael de Raadt added a comment - Test result: I tested this through the quiz export/import facility and through a course backup/restore. I ran into another issue ( MDL-29432 ), but the default grades did restore with correct default values.
        Hide
        Aparup Banerjee added a comment -

        fixes have been rolled merrily up the stream! Thanks everybody!

        Show
        Aparup Banerjee added a comment - fixes have been rolled merrily up the stream! Thanks everybody!
        Hide
        Rick Jerz added a comment -

        As the author of the original post, I too want to thank everyone for your work on fixing this problem. I wasn't sure if I should post this problem (thought that it was only something that I was experiencing), but now I am glad that I did. This really shows how everyone can help improve Moodle.

        This will really help those schools that are upgrading from 1.9+ to 2.1.

        Show
        Rick Jerz added a comment - As the author of the original post, I too want to thank everyone for your work on fixing this problem. I wasn't sure if I should post this problem (thought that it was only something that I was experiencing), but now I am glad that I did. This really shows how everyone can help improve Moodle. This will really help those schools that are upgrading from 1.9+ to 2.1.
        Hide
        Tim Hunt added a comment -

        Yes indeed. Thank you for reporting it.

        Show
        Tim Hunt added a comment - Yes indeed. Thank you for reporting it.

          People

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

            Dates

            • Created:
              Updated:
              Resolved: