General developer forum

Found more than one record in fetch() ! Error

 
Picture of John Black
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() !

More information about this error

×Debug info: 
Error code: morethanonerecordinfetch
×Stack trace:
  • 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:

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: -
Picture of Michael Aherne
Re: Found more than one record in fetch() ! Error
Core developersParticularly helpful MoodlersPlugin developers

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)
Picture of John Black
Re: Found more than one record in fetch() ! Error
 

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

 
Average of ratings: -
Picture of John Black
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


1319NULLNULLcourseNULL20NULLNULLNULLNULL1100.000000.00000NULLNULL0.000001.000000.000000.000000.00000470NULL0001015096297421509629742


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



1329NULLNULLcourseNULL20NULLNULLNULLNULL1100.000000.00000NULLNULL0.000001.000000.000000.000000.00000470NULL0001015096301181509630118

1359NULLNULLcourseNULL4NULLNULLNULLNULL1100.000000.00000NULLNULL0.000001.000000.000000.000000.00000480NULL0001015096305611509630561

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: -
Picture of Michael Aherne
Re: Found more than one record in fetch() ! Error
Core developersParticularly helpful MoodlersPlugin developers

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: -
Picture of John Black
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: -
Picture of Michael Aherne
Re: Found more than one record in fetch() ! Error
Core developersParticularly helpful MoodlersPlugin developers

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)
Picture of John Black
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: -