Error on Regrade

Error on Regrade

by Curtis Barker -
Number of replies: 20

Just upgraded to 2.2.1+ (Build: 20120217),  I can't regrade quizzes.  With full debug, I get:

Debug info: Duplicate entry '361685-2' for key 'mdl_quesattestep_queseq_uix'
UPDATE mdl_question_attempt_steps SET questionattemptid = ?,sequencenumber = ?,state = ?,fraction = ?,timecreated = ?,userid = ? WHERE id=?
[array (
0 => '361685',
1 => 2,
2 => 'gradedright',
3 => 1,
4 => '1329840836',
5 => '3565',
6 => '897468',
)]
Stack trace:
  • line 397 of /lib/dml/moodle_database.php: dml_write_exception thrown
  • line 999 of /lib/dml/mysqli_native_moodle_database.php: call to moodle_database->query_end()
  • line 1031 of /lib/dml/mysqli_native_moodle_database.php: call to mysqli_native_moodle_database->update_record_raw()
  • line 192 of /question/engine/datalib.php: call to mysqli_native_moodle_database->update_record()
  • line 1193 of /question/engine/datalib.php: call to question_engine_data_mapper->update_question_attempt_step()
  • line 91 of /question/engine/lib.php: call to question_engine_unit_of_work->save()
  • line 405 of /mod/quiz/report/overview/report.php: call to question_engine::save_questions_usage_by_activity()
  • line 449 of /mod/quiz/report/overview/report.php: call to quiz_overview_report->regrade_attempt()
  • line 162 of /mod/quiz/report/overview/report.php: call to quiz_overview_report->regrade_attempts()
  • line 100 of /mod/quiz/report.php: call to quiz_overview_report->display()

This doesn't seem to be MDL-27314 in that I can delete attempts just fine.  A dry run at regrade also seems to work, but a permanent regrade doesn't work.  Ideas, thoughts,etc?  Thanks.

Average of ratings: -
In reply to Curtis Barker

Re: Error on Regrade

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

Can you work out which question / quiz attempt is being re-graded here?

That requires a bit of work following the links between the various DB tables (http://docs.moodle.org/dev/Overview_of_the_Moodle_question_engine#Database_tables) so if you need more specific instructions than that, I can provide them. Just give me a clue as to your level of technical expertise.

Then we really need to konw what happened in that question_attempt, and what changes one would expect the regrade to make to that.

In reply to Tim Hunt

Re: Error on Regrade

by Curtis Barker -

I actually got the same error from two different quizzes in the same course.  I tried a different course and got an error writing to database (with multiple assignments).

In reply to Curtis Barker

Re: Error on Regrade

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

OK, so there may be many ways to trigger this bug. However, to get it fixed, what we need is one specific way to trigger the bug on my server. Something like:

  1. Create a new quiz
  2. Add one ... question with options ...
  3. Attempt the quiz as a student, and do this ...
  4. As teacher, regrade the quiz and see the error.

Working out the exact details that need to go into the ...s will take some time. I don't have much time at the moment, so if you want for me to investigate, I can't promise when this will be fixed. If you, or anyone else, can do the work to get some precise steps to reproduce, then I probably can find time to code the fix.

In reply to Tim Hunt

Re: Error on Regrade

by Curtis Barker -

OK, here's the best that I've got.  I simply created a quiz, added questions, and had students take it.  It was taken with the previously mentioned bug before it was fixed.  I have now tried it with quizzes created at the same time, but with no scores from before the fix was in place.  I suspect that this means that data collected with the bug is somehow causing an error in the regrade.  Once I reset the course (and delete all quiz attempts), I suspect that the regrade problem will disappear. 

I had the same problem when I tested the update in that the test server was a rebuild and didn't have old data in it from before.  I can do a restore from some backup data if I get to it to confirm the transcient nature of the error. 

If this makes, sense, give me a little time to do a restore, and we can see if this goes away with the old data.

In reply to Curtis Barker

Re: Error on Regrade

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

I am afraid that is still to vague to let me work on this productively. Hopefully someone else can reproduce it.

Acutally, hopefully it is not really a bug, just something odd with your data wink

In reply to Tim Hunt

Re: Error on Regrade

by Susana L. -

We are experiencing the same error:

----

Debug info: Duplicate entry '43115-1' for key 'mdl_quesattestep_queseq_uix'
INSERT INTO mdl_question_attempt_steps (questionattemptid,sequencenumber,state,fraction,timecreated,userid) VALUES(?,?,?,?,?,?)
[array (
0 => '43115',
1 => 1,
2 => 'gaveup',
3 => NULL,
4 => 1338894742,
5 => '45',
)]
Stack trace:

 

line 397 of /lib/dml/moodle_database.php: dml_write_exception thrown
line 893 of /lib/dml/mysqli_native_moodle_database.php: call to moodle_database->query_end()
line 935 of /lib/dml/mysqli_native_moodle_database.php: call to mysqli_native_moodle_database->insert_record_raw()
line 175 of /question/engine/datalib.php: call to mysqli_native_moodle_database->insert_record()
line 1199 of /question/engine/datalib.php: call to question_engine_data_mapper->insert_question_attempt_step()
line 91 of /question/engine/lib.php: call to question_engine_unit_of_work->save()
line 405 of /mod/quiz/report/overview/report.php: call to question_engine::save_questions_usage_by_activity()
line 449 of /mod/quiz/report/overview/report.php: call to quiz_overview_report->regrade_attempt()
line 154 of /mod/quiz/report/overview/report.php: call to quiz_overview_report->regrade_attempts()
line 100 of /mod/quiz/report.php: call to quiz_overview_report->display()

----

Moodle 2.2.1+ (Build: 20120217)
MySQL version 5.5.14
Innodb version 1.1.8

In reply to Susana L.

Re: Error on Regrade

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

That makes the cause of the failure clearer, but I don't really understand how you could get a duplicate key error when regrading if there was not one before.

However, this whole area of code changed a lot during a bug fix in 2.2.x, so trying to upgrade to Moodle 2.2.3 might fix it. Or, given that I still don't really understand what is happening, it might not.)

In reply to Tim Hunt

Re: Error on Regrade

by Samuel Witzig -
Picture of Particularly helpful Moodlers

Tim, might this bug be connected to http://moodle.org/mod/forum/discuss.php?d=198337? Brian reported the bug when doing test-upgrades from 1.9 to 2.2 for our Moodle. In the meantime, we have upgraded to 2.2.3 and regrading quizzes still results in 0.0 grades.

Would be glad if this bug could be resolved, and can send you any information you need. 

In reply to Samuel Witzig

Re: Error on Regrade

by Rolo Tomassi -

Just to echo what Samuel has said, I am also experiencing 0.0 grades following a regrade of courses migrated from 1.9 to 2.2.

Tim, have you been able to reproduce the issue?  If you need any data dumps from tables I should be able to supply this.  In the meantime we've had to deny regrade capabilities to everyone.

In reply to Rolo Tomassi

Re: Error on Regrade

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

I am afraid that I have not had time to try to reproduce this. Sorry.

In reply to Rolo Tomassi

Re: Error on Regrade

by Jessica Gramp -
Picture of Moodle HQ Picture of Plugin developers

We are also getting regrades resulting in 0 for some of our users.

I noticed a mdl_quiz_overview_regrades in the database. Perhaps this table contains a clue to what is going on. It has 2 columns one old fraction, set to 1 in most cases and the newfraction is showing as null, which could explain why some student attempts are having correct answers changed to 0.

Has any one had any luck working around or fixing this problem yet?

In reply to Jessica Gramp

Re: Error on Regrade

by Heikki Wilenius -

We also have quizzes that get 0s for correct answers after a regrade.

We started our 1.9->2.2 upgrade today. Since this was still unresolved, we just decided to send email to teachers who have active courses (luckily not many since we don't have a summer semester) warning them not to regrade  quizzes before resetting the course area.

Not a very satisfactory workaround, but a workaround none the less. =)

At least we have the 1.9 backups we can dig out if a course area gets messed up.

In reply to Heikki Wilenius

Re: Error on Regrade

by Jessica Gramp -
Picture of Moodle HQ Picture of Plugin developers

Hi Heikki

We are taking a similar approach, except that we have disabled the ability for anyone except site admins to regrade (by changing the role permissions), until we can find a solution. This way we can control all regrades to ensure quiz results aren't changed after the upgrade. 

One thing to note, when I tried to restore a Moodle 1.9 quiz in to Moodle 2.2, none of the user data came accross - just the quiz itself - so I'm not sure it's possible to recover attempts in Moodle 2 from your 1.9 backups should anyone regrade their quiz.

In reply to Jessica Gramp

Re: Error on Regrade

by Heikki Wilenius -

Hmm, I hadn't realized that, thanks for pointing it out! I wonder if restoring a full backup works?

Anyway, we're gonna keep an 1.9 installation with the old production database on a virtual server at least 6 months, so we can check out the original results if grades in a course area get messed up.

I'm tempted to disable regrading for teachers as well, but we'll probably not do this, since we only have a handful of courses running at the moment using quizzes.

In reply to Jessica Gramp

Re: Error on Regrade

by Jessica Gramp -
Picture of Moodle HQ Picture of Plugin developers

So I'm getting closer to resolving the regrading issue I think. If I manually change the null value in the newfraction column of the mdl_quiz_overview_regrades table with the value from the oldfraction column the regrade gives the same results as it did in Moodle 1.9, rather than 0. I'm assuming that if we can locate the code that is putting the null value in to the database and instead insert the same value that is being entered in to the oldfraction column then regrading will start behaving as we expect it to.

I.e. regrading in Moodle 2 will give the same results as Moodle 1.9

Can anyone see problems with this approach?

In reply to Jessica Gramp

Re: Error on Regrade

by Jessica Gramp -
Picture of Moodle HQ Picture of Plugin developers

I've noticed a few instances where the new grade in Moodle 2 is similar but slightly different from Moodle 1.9.

Running the following query shows slight differences in a couple hundred records:
SELECT * from `moodle_uat_03`.`mdl_quiz_overview_regrades` where newfraction <> oldfraction;

I'm not sure why quizzes would have changed the way grades are calculated between moodle 1 and 2.

I.e. for one answer the newfraction is slightly higher (0.9) than the oldfraction (0.8)

In other cases the newfraction is 0.9999999 and the old fraction is 0.9999900

and in others still the newfraction is 0.3333333 and the oldfraction 0.3333300.

Does anyone know why this is happening?

We're probably going to set the newfraction to be the same as the oldfraction regardless of whether it is showing as null or not, to maintain data integrity across Moodle versions.

Thanks in advance.

In reply to Jessica Gramp

Re: Error on Regrade

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

This bit is easy to explain.

In Moodle 1.9, it used different precision in different places.

In Moodle 2.0 it is defined. We use 7 decimal places for grades/fractions/marks for individual questions. When these are added up to give overall quiz (attempt) marks of grades, they get rounded to 5 decimal places.

So, that is why the old grades are approximate, and the new grades are shown to 7 d.p.

In reply to Rolo Tomassi

Re: Error on Regrade

by Tim Hunt -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

Just to note that this 'regrade changes grades to 0' but is MDL-32062, and I think I may now have a fix. See the bug for details. It would be useful if anyone can test the proposed fix.

In reply to Tim Hunt

Re: Error on Regrade

by Samuel Witzig -
Picture of Particularly helpful Moodlers

Brian applied the fix to your Moodle-server. I regraded 2 tests with several hundred attempts, and I didn't get any 0.0 values anymore. Seems like your fix is working. Should I test some more, or is that enough for you?

(btw, debugging was turned on, and there were not debug messages)

In reply to Tim Hunt

Re: Error on Regrade

by Susana L. -

Hi Tim,
This course, where we had this problem, has a peculiar story. We needed a course with students and user data on Moodle 2 to properly test gradebook, quizzes, etc... So, we restored a 1.9.13 course on a 1.9.17 local moodle instance, upgraded that instance to moodle 2.2.2+ and then did a backup and restored on our test enviornment (moodle 2.2.1+).

I don't know if this might be useful...
Please let me know if there's anything else we can do to help...