-
Bug
-
Resolution: Fixed
-
Major
-
3.3.2
-
MOODLE_33_STABLE
-
MOODLE_33_STABLE, MOODLE_34_STABLE
-
MDL-60669-master -
Note: This only seems to occur if it is a course being restored after that course has been deleted from Moodle.
After an update of our Moodle on October 20, 2017 using the Moodle 3.3.2+ release, we began noticing that course restores would fail with Moodle delivering the message: "Error writing to database"
Checking the error logs, we saw this information:
2017/11/01 13:59:55 [error] 1795#0: *5215685 FastCGI sent in stderr: "PHP message: Default exception handler: Error writing to database Debug: ERROR: duplicate key value violates unique constraint "mdl_forusubs_usefor_uix" |
DETAIL: Key (userid, forum)=(4426, 57209) already exists. |
INSERT INTO mdl_forum_subscriptions (userid,forum) VALUES($1,$2) RETURNING id |
[array (
|
'userid' => '4426', |
'forum' => 57209, |
)]
|
Error code: dmlwriteexception
|
* line 489 of /lib/dml/moodle_database.php: dml_write_exception thrown |
* line 242 of /lib/dml/pgsql_native_moodle_database.php: call to moodle_database->query_end() |
* line 886 of /lib/dml/pgsql_native_moodle_database.php: call to pgsql_native_moodle_database->query_end() |
* line 934 of /lib/dml/pgsql_native_moodle_database.php: call to pgsql_native_moodle_database->insert_record_raw() |
* line 174 of /mod/forum/backup/moodle2/restore_forum_stepslib.php: call to pgsql_native_moodle_database->insert_record() |
* line 137 of /backup/util/plan/restore_structure_step.class.php: call to restore_forum_activity_structure_step->process_forum_subscript" while reading upstream, client: 172.16.17.18, server: moodle.ourserver.org, request: "POST /backup/restore.php HTTP/1.0", upstream: "fastcgi://172.16.18.19:9000", host: "moodle.ourserver.org", referrer: "https://moodle.ourserver.org/backup/restore.php" |
Looking into the "mdl_forusubs_usefor_uix" constraint, I found an issue that had been recently resolved with the fix being rolled into 3.3.2+ here:
https://tracker.moodle.org/browse/MDL-59854
It seems that the new uniqueness constraint for the forum_submissions table is the culprit here. I was able to have course restores work properly by unchecking any discussion forum entries during the restore process. Since we sometimes need this information, I've opted to temporarily drop that new index and recreate it without the the unique keyword.
The commit that caused this issue is here:
https://git.moodle.org/gw?p=moodle.git;a=commit;h=8db207f90fbf55a3001e7b419a6b1cfe73c5c20d
and the specific database change operations are here: