I have Moodle 3.2.1
Whenever I try to add a quiz or forum or other content to any course I get this error. Any idea what could be wrong and what should I check ?
Found more than one record in fetch() !
Error code: morethanonerecordinfetch
- line 496 of /lib/setuplib.php: moodle_exception thrown
- line 163 of /lib/grade/grade_object.php: call to print_error()
- line 354 of /lib/grade/grade_item.php: call to grade_object::fetch_helper()
- line 1125 of /lib/grade/grade_item.php: call to grade_item::fetch()
- line 1124 of /lib/gradelib.php: call to grade_item::fetch_course_item()
- line 345 of /course/modlib.php: call to grade_regrade_final_grades()
- line 173 of /course/modlib.php: call to edit_module_post_actions()
- line 161 of /course/modedit.php: call to add_moduleinfo()
The only problem I could find was:
However php admin/cli/mysql_compressed_rows.php --list return this (as far as I understand it means DB format ok):
We've seen that error before. It means there are two "course" records in the grade_items table for some course, when there should be only one. As far as we could work out this is something to do with the fact that the grade API creates the course item on-the-fly if it doesn't exist when it's needed, so you can end up with two if you're unlucky.
If you run this SQL it should show you the offending course(s):
select courseid, count(*) from mdl_grade_items where itemtype = 'course' group by courseid having count(*) > 1
Unfortunately I can't remember how to fix it, but I think it may have been as simple as deleting the record with the higher ID.
Thanks for your quick help
Looks like I have 3 courses with these problems
| courseid | count(*) |
| 8 | 2 |
| 9 | 2 |
| 10 | 2 |
3 rows in set (0.00 sec)
Now I just need to figure out how to fix it
I removed the duplicate records manually, but I still get the same error when I try to add quiz.
I also see that after I manually remove the second record I try to add a quiz and get the same error, but when I go back to the DB I see that I new record is added
If I remove all course records from a specific course and then try to add a quiz I still get an error and two records are added
Any idea whats going on ?
BTW its happening in all my existing courses, but if I create a new course everything is ok in this new one
I think that only "hotpot"
Also I'm not sure if it suppose to be like that or not, but I also have two "category" records in this course and also if I remove them when I try to add a quiz it adds two new records
That kind of makes sense - they'll be the root categories for the course, so if you've got two course records you should get two of those too. Sounds like the duplicate course items is definitely the root of your issues, but I really don't understand why it might be happening, so not sure how much more help I can be!
Thank you very much for your help
I will try to upgrade Moodle to the latest version tomorrow, just in case its some bug that was fixed
Whoever found a solution to the problem, I have the same situation
We have had a similar issue and were unable to delete the problematic course. In the end we deleted records manually in the Moodle database
deleted records related to the courseid of the problematic course. We could then delete the course.
The problem was caused by two users creating assignments in the same course at exactly the same time. How did we manage to do this you might well ask - I was talking through a new Moodle admin person on the phone who needed to create a copy of a course which had two assignments. So I was telling them what to put on all the sections and to save time they added one while I added the other!
Just a quick note, the duplicate entry with the higher ID will be created time and time again when viewing grader reports, but deleting the duplicates with the lower ID's seems to do the trick.