I have an external script that imports courses into moodle by essentially copying an existing course and all of its settings/assignments/etc. All is well until I edit a quiz. After that, any graded activity (assignment, quiz) throws the error "more than one record in fetch()". Prior to clicking the "edit settings" link, there is a single record in the grade_items table with the itemtype = 'course' and the iteminstance = the course ID. When I click the link to edit the settings, the following happens: the grade_item course (itemtype="course") record is duplicated but the itemtype is set to "category", and any grade_item category (itemtype="category") records are duplicated, but the itemtype is set to "course".
I have posted a comment in Jira for issue MDL-29045, which is currently unassigned, but was created nearly two years ago. I know this issue was addressed prior to 2.3, but I am running 2.4. Quick help would be GREATLY appreciated; we are unable to go live with this version of moodle if this error continues.