What could be the cause?
[Thu Feb 19 14:34:58 2015] [error] [client 10.10.10.172] Default exception handler: Error writing to database Debug: Duplicate entry '62864' for key 'mdl15_quesshor_que_uix'\nINSERT INTO mdl15_qtype_shortanswer_options (usecase,questionid) VALUES(?,?)\n[array (\n 0 => '0',\n 1 => 62864,\n)]\nError code: dmlwriteexception\n* line 446 of /lib/dml/moodle_database.php: dml_write_exception thrown\n* line 1164 of /lib/dml/mysqli_native_moodle_database.php: call to moodle_database->query_end()\n* line 1210 of /lib/dml/mysqli_native_moodle_database.php: call to mysqli_native_moodle_database->insert_record_raw()\n* line 74 of /question/type/shortanswer/backup/moodle2/restore_qtype_shortanswer_plugin.class.php: call to mysqli_native_moodle_database->insert_record()\n* line 137 of /backup/util/plan/restore_structure_step.class.php: call to restore_qtype_shortanswer_plugin->process_shortanswer()\n* line 103 of /backup/util/helper/restore_structure_parser_processor.class.php: call to restore_structure_step->process()\n* line 151 of /backup/util/xml/parser/processors/grouped_parser_processor.class.php: call to restore_structure_parser_processor->dispatch_chunk()\n* line 91 of /backup/util/helper/restore_structure_parser_processor.class.php: call to grouped_parser_processor->postprocess_chunk()\n* line 148 of /backup/util/xml/parser/processors/simplified_parser_processor.class.php: call to restore_structure_parser_processor->postprocess_chunk()\n* line 92 of /backup/util/xml/parser/processors/progressive_parser_processor.class.php: call to simplified_parser_processor->process_chunk()\n* line 190 of /backup/util/xml/parser/progressive_parser.class.php: call to progressive_parser_processor->receive_chunk()\n* line 278 of /backup/util/xml/parser/progressive_parser.class.php: call to progressive_parser->publish()\n* line ? of unknownfile: call to progressive_parser->end_tag()\n* line 179 of /backup/util/xml/parser/progressive_parser.class.php: call to xml_parse()\n* line 158 of /backup/util/xml/parser/progressive_parser.class.php: call to progressive_parser->parse()\n* line 110 of /backup/util/plan/restore_structure_step.class.php: call to progressive_parser->process()\n* line 181 of /backup/util/plan/base_task.class.php: call to restore_structure_step->execute()\n* line 177 of /backup/util/plan/base_plan.class.php: call to base_task->execute()\n* line 167 of /backup/util/plan/restore_plan.class.php: call to base_plan->execute()\n* line 333 of /backup/controller/restore_controller.class.php: call to restore_plan->execute()\n* line 184 of /backup/util/ui/restore_ui.class.php: call to restore_controller->execute_plan()\n* line 107 of /backup/restore.php: call to restore_ui->execute()\n, referer: http://moodle.example.com/backup/restore.php
[Thu Feb 19 14:34:58 2015] [error] [client 10.10.10.172] Potential coding error - existing temptables found when disposing database. Must be dropped!, referer: http://moodle.example.com/backup/restore.php
This looks very similar to MDL-40370. That bug related to what happens if you upgraded an old site that had bad data, but the same problem could happen if you make a backup on an old site (2.4 or older) and try to restore it on a newer one.
The point is that there should be exactly one row in the qtype_shortanswe_options table for each short-answer question. In the past, that constraint was not enforced, and in some strange situations you got two rows. Now we do enforce the constraint, so if a question in the backup file has more than one row, you get an error like this.
I guess we should make the restore code ignore any duplicates. MDL-49247
Many thanks for the clarification! One question though: The course backups we are trying to restore are fairly recent, means taken in the same 2.7.3 Moodle. Does it have any effect on the diagnosis?
Assuming it is MDL-49247, is there anything I can do restore the course in short term? I have direct access to the database. I was recent acitvity in MDL-49247. Should I wait?
Can you try some queries like
SELECT questionid, count(1)
GROUP BY questionid
HAVING count(1) > 1
That will tell you if your database has any short-answer questions with duplicate options rows. If there are, then that confirms the diagnosis.
You could also then try cleaning up the duplicates by hand.
There are no short-answer duplicates (the querry above returns Empty set). So this is not the case.
To make things complicated the admin says that now he can restore the same courses without this problem! I don't know where to start, not a good situation.
Might help to raise debug to maximum and go through a (successfull) restore. Will report back.