From e12c760a1239df820cd0af22bbe247a98b3e98b2 Mon Sep 17 00:00:00 2001 From: "Eloy Lafuente (stronk7)" <stronk7@moodle.org> Date: Mon, 8 May 2023 18:18:54 +0200 Subject: [PATCH] MDL-78156 groups: Make groups_get_user_groups() order deterministic 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(). --- lib/grouplib.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/grouplib.php b/lib/grouplib.php index 94730d3eed7..a6f9388fd1a 100644 --- a/lib/grouplib.php +++ b/lib/grouplib.php @@ -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();