When recovering a users grades on enrolment, Moodle will sometimes fatal error.
----
Debug info: ORA-00001: unique constraint (MOODLE.M_GRADGRAD_USEITE_UIX) violated
INSERT INTO mdl_grade_grades (itemid,userid,rawgrade,rawgrademax,rawgrademin,rawscaleid,usermodified,finalgrade,hidden,locked,locktime,exported,overridden,excluded,timecreated,timemodified,aggregationstatus,aggregationweight) VALUES (:itemid,:userid,:rawgrade,:rawgrademax,:rawgrademin,:rawscaleid,:usermodified,:finalgrade,:hidden,:locked,:locktime,:exported,:overridden,:excluded,:timecreated,:timemodified,:aggregationstatus,:aggregationweight) RETURNING id INTO :oracle_id
[array (
'itemid' => '18429',
'userid' => '7291',
'rawgrade' => NULL,
'rawgrademax' => 100,
'rawgrademin' => 0,
'rawscaleid' => NULL,
'usermodified' => NULL,
'finalgrade' => NULL,
'hidden' => 0,
'locked' => 0,
'locktime' => 0,
'exported' => 0,
'overridden' => 0,
'excluded' => 0,
'timecreated' => NULL,
'timemodified' => NULL,
'aggregationstatus' => 'unknown',
'aggregationweight' => NULL,
)]
Error code: dmlwriteexception
Stack trace:
- line 489 of /lib/dml/moodle_database.php: dml_write_exception thrown
- line 277 of /lib/dml/oci_native_moodle_database.php: call to moodle_database->query_end()
- line 1289 of /lib/dml/oci_native_moodle_database.php: call to oci_native_moodle_database->query_end()
- line 1336 of /lib/dml/oci_native_moodle_database.php: call to oci_native_moodle_database->insert_record_raw()
- line 343 of /lib/grade/grade_object.php: call to oci_native_moodle_database->insert_record()
- line 1009 of /lib/grade/grade_grade.php: call to grade_object->insert()
- line 614 of /lib/grade/grade_category.php: call to grade_grade->insert()
- line 561 of /lib/grade/grade_category.php: call to grade_category->aggregate_grades()
- line 736 of /lib/grade/grade_item.php: call to grade_category->generate_grades()
- line 1256 of /lib/gradelib.php: call to grade_item->regrade_final_grades()
- line 2017 of /lib/grade/grade_item.php: call to grade_regrade_final_grades()
- line 284 of /lib/gradelib.php: call to grade_item->update_raw_grade()
- line 842 of /mod/quiz/lib.php: call to grade_update()
- line 734 of /mod/quiz/lib.php: call to quiz_grade_item_update()
- line 1381 of /lib/gradelib.php: call to quiz_update_grades()
- line 1351 of /lib/gradelib.php: call to grade_update_mod_grades()
- line 1105 of /lib/gradelib.php: call to grade_grab_course_grades()
- line 1915 of /lib/enrollib.php: call to grade_recover_history_grades()
- line 794 of /enrol/imsenterprise/lib.php: call to enrol_plugin->enrol_user()
- line 214 of /enrol/imsenterprise/lib.php: call to enrol_imsenterprise_plugin->process_membership_tag()
- line 69 of /enrol/imsenterprise/importnow.php: call to enrol_imsenterprise_plugin->cron()
-----
Environment:
- Moodle version 3.4.x
- Oracle DB
I'm looking for a code solution here - I suspect that around a user's grade-item restore, either:
- a try-catch->ignore is missing (e.g. somewhere around regrade_final_grades()); or
- Oracle is not admitting that the grade item already exists
In trying to track this down one quickly gets into the depths of grade item recalculation...
Any hints?