-
Bug
-
Resolution: Fixed
-
Minor
-
2.7.2
-
MOODLE_27_STABLE
-
MOODLE_27_STABLE, MOODLE_28_STABLE
-
When attempting to view /admin/roles/assign.php?contextid=177&roleid=5
the following error message is received:
Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 32 bytes) in /vle/www_root/lib/dml/pgsql_native_moodle_database.php on line 787
On this particular system the sql: SELECT ra.id AS raid,u.id,u.firstnamephonetic,u.lastnamephonetic,u.middlename,u.alternatename,u.firstname,u.lastname,u.username,u.idnumber,ra.contextid,ra.component
FROM mdl_role_assignments ra
JOIN mdl_user u ON u.id = ra.userid
JOIN mdl_context ctx ON ra.contextid = ctx.id
WHERE u.id <> 1
AND u.deleted = 0
AND u.confirmed = 1
AND ctx.id IN (177,86,97,95,1)
AND ra.roleid = 5
ORDER BY ctx.depth DESC, ra.component, u.lastname, u.firstname, u.id
produces 60043 rows.
The error is due to the memory usage of the arrays used to process these results.
In other admin screens the $this->maxusersperpage variable is used to prevent this processing being attempted where tuples to display may cause such issues.
Moving original testing instructions here
Find a context where you have around 40,000 users (my test had 40,921 users, one with 26,058 worked without error) assigned to a particular role. I used the query:
select count(1),contextid, roleid from mdl_role_assignments
group by contextid,roleid
order by 1 desc
and then request /admin/roles/assign.php?contextid=<contextid>&roleid=<roleid>, and with debugging on you should get the error: 'Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 9 bytes) in /vle/www_root/lib/dml/pgsql_native_moodle_database.php on line 787' or similar depending on your script location.
Once this change is applied you should not receive this error and the page should display correct, and rather than displaying the list of users with the role currently assigned the box should display: 'Too many users (xxxxx) to show Please use search'