Skip to content

Commit

Permalink
MDL-78156 groups: Make groups_get_user_groups() order deterministic
Browse files Browse the repository at this point in the history
Right now the order of the groups returned by groups_get_user_groups()
is not fixed and, every DB, can return them in any order. While 99%
of times the order will be the creation one, depending of the RDBMS
decisions, they can be returned in any order.

This is specially noticeable with Oracle, but can affect to any DB.

And that makes some tests (expecting a given order) to fail.

This commit fixes the problem by making the order of the groups
deterministic, because that's the way we use to fix these problems.

Alternative is to relax the tests so only values are asserted by
using assertEqualsCanonicalizing().
  • Loading branch information
stronk7 committed May 8, 2023
1 parent 5d320dd commit e12c760
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/grouplib.php
Original file line number Diff line number Diff line change
Expand Up @@ -489,6 +489,8 @@ function groups_get_user_groups($courseid, $userid=0) {
$params = array_merge($params, $visibilityparams);
}

$sql .= ' ORDER BY g.id'; // To make results deterministic.

$rs = $DB->get_recordset_sql($sql, $params);

$usergroups = array();
Expand Down

0 comments on commit e12c760

Please sign in to comment.