moodle-tool_mergeusers icon indicating copy to clipboard operation
moodle-tool_mergeusers copied to clipboard

Tool mistakenly calls course_module_instance_pending_deletion() on a module not pending deletion, then calls get_course() with module's id

Open freeradicalx opened this issue 4 years ago • 1 comments

Hi there, I've successfully troubleshooted a lot of failed user merges with this tool, almost always a result of some record or another in the database being missing, or some adhoc task not being run. However this one has me stumped and I suspect a coding issue in tool_mergeuser this time. Stack trace:

Exception thrown when merging: 'Can't find data record in database table course.".

Trace:
#0 /var/www/drury/lib/dml/moodle_database.php(1575): moodle_database->get_record_select('course', 'WHERE id = ?', Array, '*', 2)
#1 /var/www/drury/lib/datalib.php(591): moodle_database->get_record('course', Array, '*', 2)
#2 /var/www/drury/lib/modinfolib.php(448): get_course('13881', false)
#3 /var/www/drury/lib/modinfolib.php(417): course_modinfo->__construct(Object(stdClass), '2')
#4 /var/www/drury/lib/modinfolib.php(2168): course_modinfo::instance('13881', '2')
#5 /var/www/drury/course/lib.php(1249): get_fast_modinfo('13881')
#6 /var/www/drury/lib/grade/grade_item.php(595): course_module_instance_pending_deletion('13881', 'forum', '39379')
#7 /var/www/drury/lib/gradelib.php(133): grade_item->is_locked()
#8 /var/www/drury/mod/forum/lib.php(902): grade_update('mod/forum', '13881', 'mod', 'forum', '39379', 0, NULL, Array)
#9 /var/www/drury/lib/gradelib.php(1397): forum_grade_item_update(Object(stdClass))
#10 /var/www/drury/admin/tool/mergeusers/lib/mergeusertool.php(471): grade_update_mod_grades(Object(stdClass), '93394')
#11 /var/www/drury/admin/tool/mergeusers/lib/mergeusertool.php(271): MergeUserTool->updateGrades('93394', '82783')
#12 /var/www/drury/admin/tool/mergeusers/lib/mergeusertool.php(192): MergeUserTool->_merge('93394', '82783')
#13 /var/www/drury/admin/tool/mergeusers/index.php(135): MergeUserTool->merge('93394', '82783')
#14 {main}

Started merging at Monday, November 30, 2020, 11:22 AM
Merge took 5 seconds

At #8 we call grade_update() on a forum module, but this particular forum module is an empty and ungraded announcements forum at the top of one course. Not sure why it's trying to update it's grade.

Then at #6 we call course_module_instance_pending_deletion(), despite there being no pending deletions in mdl_task_adhoc.

Then, strangest of all, at #2 we call get_course() on that same module id as if it's actually a course? This is why I suspect a coding error. There is certainly no course with that id in the database, and up until that point we are using this id as a module identifier.

If any further info is needed let me know and I may be able to supply. Thank you!

freeradicalx avatar Nov 30 '20 17:11 freeradicalx

Hi!

Thanks for the feedback.

There is another issue that resembles to this: somehow Moodle core does not work properly when updating grades, in a weird manner.

From this plugin, we cannot interfere in the Moodle core API, code or behaviour. Instead, we have to rely on them.

We pass the necessary information to regrading activities, if it's necessary. Every plugin address this task properly.

It seems like there is some kind of misconfiguration, inconsistence or orphan records that makes grading behaving this way. Think that it's what it is expected to do. We just invoke the Moodle API for regrading every module.

We have this plugin in our production site, with announcements forums too, and I cannot recall any issue like this.

If you can research on the database model, records, to detect any inconsistence, would be the next step for solving this issue.

Right now, it's what I can say.

Thanks for your time.

jpahullo avatar Jun 10 '21 22:06 jpahullo