Likely bug in Participants list (user/index.php)

Likely bug in Participants list (user/index.php)

by Garret Gengler -
Number of replies: 0

Greetings...  I just reported this bug in the tracker:
http://tracker.moodle.org/browse/MDL-10537

Our installation is version 1.7, so I don't know for sure that this bug affects newer versions.  But from studying the code, I believe it will.

If someone can test this on the latest code, and reproduce the problem, that would be great.   Eventually I'll get a test platform of 1.8 installed, and upgrade our site to that version (we have some local customizations, so it's nontrivial.) 

... but that might be  awhile, and I'm afraid in the meantime, this bug will get lost in the tracker, buried among other 1.7.x bugs.

Here's my description of the bug...

---------------------------------------------------------

Bear with me.. this one is tricky to describe. But we can reproduce it easily, and I've been studying the code for two days,so I'm pretty sure it's a real bug.

There is a bug in the user/index.php page that causes users to sometimes not display.

It occurs when you have a number of unique participants <20, but a number of "non-hidden" role assignments greater than 20.

Throughout this code, SELECT DISTINCT is used to count users... but there is one place where it is not used. In version 1.142, see line 323. That query does not use DISTINCT, so it will retrieve duplicate rows for any user who has more than one "non-hidden" role in the course.

Maybe you have 23 role assignments, but only 19 unique users. The Participants page will say something like 19 total participants, but if you count the people (rows), you will see only 17. Get_record_sql is retrieving just the first 20 records out of the 23 role assignments. Among that set of rows are 17 unique people. But the total count of unique users is <20, so you don't see paging commands. You just see one page, which says 19 users at the top, but has only 17 table rows.

We noticed this because in one of our classes, we accidentally gave four Teaching Assistants a TA role and an Instructor Role. So we can easily fix the data and avoid this bug. There are other situations, however, where we need to have users with more than one non-hidden role... In several classes, a student in the class has been selected to act as a Teaching Assistant. So, that's a valid situation where the bug would apply if the count of students is just right...

The fix is easy: just change the query on line 323 to SELECT DISTINCT.

Important note: I have not tested this on any version of Moodle other than 1.7. From looking at the code, it appears that it will happen with the latest code, but I can't tell you for sure. In the latest version of the code (v1.179), the offending query is on line 328.

If you have trouble reproducing this, I can set up a demonstration class for you.

Best regards,
-Garret

Average of ratings: -