Details
-
Bug
-
Status: Open
-
Minor
-
Resolution: Unresolved
-
3.9.20, 3.11.13, 4.0.8, 4.1.2, 4.2
-
None
-
MOODLE_311_STABLE, MOODLE_39_STABLE, MOODLE_400_STABLE, MOODLE_401_STABLE, MOODLE_402_STABLE
-
MDL-77619-master
Description
Issue
We've noticed on a few sites occasionally the gradebook page will display an error "Found more than one record in fetch() !"
This error comes from there being multiple grade_items of type "course" in the grade_items table.
This is likely happening because of a race condition and has become more likely because of MDL-19711 .
The grade category has a function that checks if any grade items exist, and if none exist it creates one. This means its possible for two scripts to race and the check for existing grade items doesn't work and two grade items are created, leading to errors elsewhere.
It is quite rare, but does still happen. Which makes me think it's usually when backing up / restoring courses.
How to reproduce
- Setup a Moodle site
- Create a course
- In this file, https://github.com/moodle/moodle/blob/master/lib/grade/grade_category.php#L2275 under this line add the line: sleep(5)
- Open two tabs / sessions and login to the site and go to the course.
- In the first tab, open the gradebook and quickly switch to the second tab and open the gradebook as well.
- Wait a couple of seconds for the sleep to pass
- The second tab will give an exception "Found more than one record in fetch()"
- If you check the grade_items table, you can see two grade_items created for the course
Notes
- I only tested course grade items (categories). But it seems this is able to affect anything that uses this function. So its likely it also affects activity grade items as well