Okay, I downloaded the latest 1.7 release, and it appears that this bug is fixed. If you look in the lib/accesslib.php file and the get_users_by_capability function has lines that look like
/// Construct the main
SQL $select = " SELECT $fields";
$from = " FROM {$CFG->prefix}user u
INNER JOIN {$CFG->prefix}role_assignments ra ON ra.userid = u.id INNER JOIN {$CFG->prefix}role r ON r.id = ra.roleid
LEFT OUTER JOIN {$CFG->prefix}user_lastaccess ul ON ul.userid = u.id
$groupjoin";
$where = " WHERE ra.contextid ".get_related_contexts_string($
context)."
AND u.deleted = 0
AND ra.roleid in $roleids
$exceptionsql
$coursesql
$groupsql";
instead of
/// Construct the main SQL
$select = " SELECT $fields";
$from = " FROM {$CFG->prefix}user u
INNER JOIN {$CFG->prefix}role_assignments ra ON ra.userid = u.id INNER JOIN {$CFG->prefix}role r ON r.id = ra.roleid
LEFT OUTER JOIN {$CFG->prefix}user_lastaccess ul ON (ul.userid = u.id $coursesql1)
$groupjoin";
$where = " WHERE ra.contextid ".get_related_contexts_string($context)."
AND u.deleted = 0
AND ra.roleid in $roleids
$exceptionsql
$groupsql";
Then you need to upgrade.