Details
-
Bug
-
Status: Open
-
Minor
-
Resolution: Unresolved
-
3.9.14
-
None
-
MOODLE_39_STABLE
Description
It's been recorded at least twice.
Revealed by mod_forum\task\send_user_notifications adhoc task failing with the following error:
Server Time: Tue, 17 May 2022 08:04:57 +1000 |
|
Execute adhoc task: mod_forum\task\send_user_notifications
|
... started 08:04:57. Current memory use 18.3MB. |
Sending messages to username (597437) |
Post 7284305 sent |
Sent 1 messages with 0 failures |
Marking posts as read
|
... used 1362 dbqueries |
... used 13.363181114197 seconds |
Adhoc task failed: mod_forum\task\send_user_notifications,Error writing to database (ERROR: duplicate key value violates unique constraint "mdl_foruread_posuse_uix" |
DETAIL: Key (postid, userid)=(7284305, 597437) already exists. |
INSERT INTO mdl_forum_read (userid, postid, discussionid, forumid, firstread, lastread)
|
|
SELECT $1, p.id, p.discussion, d.forum, $2, $3 |
FROM mdl_forum_posts p
|
JOIN mdl_forum_discussions d ON d.id = p.discussion
|
JOIN mdl_forum f ON f.id = d.forum
|
LEFT JOIN mdl_forum_track_prefs tf ON (tf.userid = $4 AND tf.forumid = f.id) |
LEFT JOIN mdl_forum_read fr ON (
|
fr.userid = $5 |
AND fr.postid = p.id
|
AND fr.discussionid = d.id
|
AND fr.forumid = f.id
|
)
|
WHERE p.id = $6 |
AND p.modified >= $7 |
AND (f.trackingtype = 2 |
OR (f.trackingtype = 1 AND tf.id IS NULL)) |
AND fr.id IS NULL
|
[array (
|
0 => '597437', |
1 => 1652738710, |
2 => 1652738710, |
3 => '597437', |
4 => '597437', |
5 => 7284305, |
6 => 1621202710, |
)])
|
Debug info:
|
ERROR: duplicate key value violates unique constraint "mdl_foruread_posuse_uix" |
DETAIL: Key (postid, userid)=(7284305, 597437) already exists. |
INSERT INTO mdl_forum_read (userid, postid, discussionid, forumid, firstread, lastread)
|
|
SELECT $1, p.id, p.discussion, d.forum, $2, $3 |
FROM mdl_forum_posts p
|
JOIN mdl_forum_discussions d ON d.id = p.discussion
|
JOIN mdl_forum f ON f.id = d.forum
|
LEFT JOIN mdl_forum_track_prefs tf ON (tf.userid = $4 AND tf.forumid = f.id) |
LEFT JOIN mdl_forum_read fr ON (
|
fr.userid = $5 |
AND fr.postid = p.id
|
AND fr.discussionid = d.id
|
AND fr.forumid = f.id
|
)
|
WHERE p.id = $6 |
AND p.modified >= $7 |
AND (f.trackingtype = 2 |
OR (f.trackingtype = 1 AND tf.id IS NULL)) |
AND fr.id IS NULL
|
[array (
|
0 => '597437', |
1 => 1652738710, |
2 => 1652738710, |
3 => '597437', |
4 => '597437', |
5 => 7284305, |
6 => 1621202710, |
)]
|
Backtrace:
|
* line 336 of /lib/dml/pgsql_native_moodle_database.php: call to moodle_database->query_end() |
* line 784 of /lib/dml/pgsql_native_moodle_database.php: call to pgsql_native_moodle_database->query_end() |
* line 4396 of /mod/forum/lib.php: call to pgsql_native_moodle_database->execute() |
* line 174 of /mod/forum/classes/task/send_user_notifications.php: call to forum_tp_mark_posts_read() |
* line 357 of /lib/cronlib.php: call to mod_forum\task\send_user_notifications->execute() |
* line 198 of /lib/cronlib.php: call to cron_run_inner_adhoc_task() |
* line 131 of /admin/cli/adhoc_task.php: call to cron_run_adhoc_tasks() |
|
Ran 1 adhoc tasks found at Tue, 17 May 2022 08:04:57 +1000 |
I've done some basic research and found that:
- Post id 7284305 with discussion 2785630 was created by user id 597437 on 1649650337 (Monday, 11 April 2022 г., 14:12:17).
- Post id 7284305 for discussion id 2784477 was read by user id 597437 on 1649650337 (Monday, 11 April 2022 г., 14:12:17).
- Forum discussion id 2785630 was created by userid 597437 and modified by userid 597437 on 1649650337 (Monday, 11 April 2022 г., 14:12:17).
- Forum discussion id 2784477 was created by userid 6831 and modified by user id 597437 on 1649732183 (Tuesday, 12 April 2022 г., 12:56:23).
It's hard to say the exact time the adhoc task was created due to MDL-74775.
it looks like user id 597437 modified (or created a discussion), then created a post, read the post automatically (same timestamp) and then for some reason this post was re-linked to another discussion with higher id that was modified next day.
The workaround is to re-link forum read record to correct discussion:
UPDATE mdl_forum_read SET discussionid = 2785630 WHERE postid = 7284305 AND userid = 597437 AND discussionid = 2784477; |
UPDATE mdl_task_adhoc SET nextruntime = 1 WHERE id = 169887241; |