## General developer forum

### Found more than one record in fetch() ! Error

Found more than one record in fetch() ! Error

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() !

×Debug info:
Error code: morethanonerecordinfetch
×Stack trace:
• line 496 of /lib/setuplib.php: moodle_exception thrown
• 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:

## Other checks

InformationReportPluginStatus
check_mysql_file_format

unsupporteddbfileformat

Error

However php admin/cli/mysql_compressed_rows.php --list  return this (as far as I understand it means DB format ok):

mdl_data                        Compressed

mdl_data_fields                 Compressed

mdl_enrol_lti_lti2_consumer     Compressed

mdl_enrol_paypal                Compressed

mdl_hotpot                      Compressed

mdl_hotpot_cache                Compressed

mdl_lti                         Compressed

mdl_user                        Compressed

mdl_user_info_field             Compressed

Average of ratings: -
Re: Found more than one record in fetch() ! Error

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.

Average of ratings: Useful (1)
Re: Found more than one record in fetch() ! Error

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

Average of ratings: -
Re: Found more than one record in fetch() ! Error

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

 131 9 NULL NULL course NULL 20 NULL NULL NULL NULL 1 100 0 NULL NULL 0 1 0 0 0 47 0 NULL 0 0 0 1 0 1509629742 1509629742

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

 132 9 NULL NULL course NULL 20 NULL NULL NULL NULL 1 100 0 NULL NULL 0 1 0 0 0 47 0 NULL 0 0 0 1 0 1509630118 1509630118

 135 9 NULL NULL course NULL 4 NULL NULL NULL NULL 1 100 0 NULL NULL 0 1 0 0 0 48 0 NULL 0 0 0 1 0 1509630561 1509630561

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

Average of ratings: -
Re: Found more than one record in fetch() ! Error

Sorry, haven't a clue what could be happening there! I don't really understand why you'd have 2 new course items created on adding a quiz. Do you have any non-core plugins installed?

Average of ratings: -
Re: Found more than one record in fetch() ! Error

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

Average of ratings: -
Re: Found more than one record in fetch() ! Error

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!

Average of ratings: Useful (1)
Re: Found more than one record in fetch() ! Error

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

Average of ratings: -