-
Bug
-
Resolution: Fixed
-
Minor
-
3.2.4, 3.3.1, 3.4
-
MOODLE_32_STABLE, MOODLE_33_STABLE, MOODLE_34_STABLE
-
MOODLE_32_STABLE, MOODLE_33_STABLE
-
MDL-59854-master -
In our production system I just found the following exception message, when displaying the newsletter forum of our site course:
Did you remember to make the first column something unique in your call to get_records? Duplicate value '24028' found in column 'id'.
- line 807 of /lib/dml/pgsql_native_moodle_database.php: call to debugging()
- line 456 of /mod/forum/classes/subscriptions.php: call to pgsql_native_moodle_database->get_records_sql()
- line 114 of /mod/forum/subscribers.php: call to mod_forum\subscriptions::fetch_subscribed_users()
Indeed, for multiple forums of our production system, there exist duplicate subscriptions for the same users. They are not many, but they exist:
count | userid | forum
------++--------------
2 | 52425 | 43775
2 | 27997 | 51392
2 | 24028 | 1
2 | 29475 | 51392
2 | 39667 | 36421
2 | 6984 | 51392
2 | 38646 | 48737
2 | 38646 | 51740
2 | 14616 | 51740
2 | 21720 | 51392
2 | 54188 | 51740
2 | 54188 | 48737
2 | 36801 | 51740
2 | 46257 | 16885
Looking at the subscribe function, there is a race condition, between checking if a subscription exists and creating a new one:
public static function subscribe_user($userid, $forum, $context = null, $userrequest = false) { |
global $DB;
|
|
if (self::is_subscribed($userid, $forum)) { |
return true; |
}
|
|
$sub = new \stdClass(); |
$sub->userid = $userid;
|
$sub->forum = $forum->id;
|
|
$result = $DB->insert_record("forum_subscriptions", $sub); |