Moodle

Undefined property: stdClass::$id in /.../lib/accesslib.php on line 4727

Details

  • Type: Bug Bug
  • Status: Closed Closed
  • Priority: Major Major
  • Resolution: Fixed
  • Affects Version/s: 1.9.3
  • Fix Version/s: 1.9.4
  • Component/s: Roles / Access
  • Labels:
    None
  • Affected Branches:
    MOODLE_19_STABLE
  • Fixed Branches:
    MOODLE_19_STABLE

Description

I just did an upgrade on my 1.9 test site to build 2007101533.01 and Moodle is now throwing the above notice hundreds of times on every page. It's this bit of code...

4718
4719 //error_log(" Record: " . print_r($user,1));
4720
4721 //
4722 // Pagination controls
4723 // Note that we might end up removing a user
4724 // that ends up not having the rights,
4725 // therefore rolling back $c
4726 //
4727 if ($lastuserid != $user->id) {
4728

Granted, it could be a local issue on my test site, but I thought I'd better report it to be safe!!

Activity

Hide
Howard Miller added a comment -

Dumped the object (just whatever the first time it was called) and...

stdClass Object
(
[username] => guest
[firstname] => Guest User
[lastname] =>
[roleid] =>
[depth] =>
)

Show
Howard Miller added a comment - Dumped the object (just whatever the first time it was called) and... stdClass Object ( [username] => guest [firstname] => Guest User [lastname] => [roleid] => [depth] => )
Hide
Howard Miller added a comment -

Yet more info.... This is an example of the SQL that generates that recordset...

SELECT username,firstname,lastname ,ra.roleid, ra.depth FROM (SELECT u.id as userid, ra.roleid,
ctx.depth
FROM mdl_user u..........

So it's possibly what gets passed into get_users_by_capability() in the $fields parameter that's the problem?

Show
Howard Miller added a comment - Yet more info.... This is an example of the SQL that generates that recordset... SELECT username,firstname,lastname ,ra.roleid, ra.depth FROM (SELECT u.id as userid, ra.roleid, ctx.depth FROM mdl_user u.......... So it's possibly what gets passed into get_users_by_capability() in the $fields parameter that's the problem?
Hide
Howard Miller added a comment -

Sorry... more info... the call path leads back to the constructor for this class...

class admin_setting_users_with_capability

in adminlib.php. The change in question (by Tim) is here:

http://cvs.moodle.org/moodle/lib/adminlib.php?r1=1.153.2.57&r2=1.153.2.58

Adding id to the list of fields seems to fix it. I have no idea what this is all for so I am reluctant to commit this myself

Show
Howard Miller added a comment - Sorry... more info... the call path leads back to the constructor for this class... class admin_setting_users_with_capability in adminlib.php. The change in question (by Tim) is here: http://cvs.moodle.org/moodle/lib/adminlib.php?r1=1.153.2.57&r2=1.153.2.58 Adding id to the list of fields seems to fix it. I have no idea what this is all for so I am reluctant to commit this myself
Hide
Tim Hunt added a comment -

Ah right. That is a new admin_setting class that I wrote recently, and I screwed up by trying to limit the list of fields too much. Yes, adding id to the list of fields is the correct fix. has_cap requires it.

However, the problem only occurs in the more complex branch of the code which is used when there are negative permissions like PREVENT and PROHIBIT, which is more rarely used, which is probably why other people have not seen this.

Acutally, we should check that u.id is in the list of fields, and if not display a nice error if not. I'll fix it.

Show
Tim Hunt added a comment - Ah right. That is a new admin_setting class that I wrote recently, and I screwed up by trying to limit the list of fields too much. Yes, adding id to the list of fields is the correct fix. has_cap requires it. However, the problem only occurs in the more complex branch of the code which is used when there are negative permissions like PREVENT and PROHIBIT, which is more rarely used, which is probably why other people have not seen this. Acutally, we should check that u.id is in the list of fields, and if not display a nice error if not. I'll fix it.
Hide
Tim Hunt added a comment -

Thanks for the clear report and diagnosis Howard.

Show
Tim Hunt added a comment - Thanks for the clear report and diagnosis Howard.
Hide
MurielB added a comment -

hi,
i update today (20090115) my moodle 1.9.3 to 1.9.3+ (build 20090114)
i've got this error after the update :
Notice: Undefined property: stdClass::$id in /moodle/lib/accesslib.php on line 4727
i read your report but don't understand what i have to do to fix this bug ...

please can you tell me more ?

thanks

Show
MurielB added a comment - hi, i update today (20090115) my moodle 1.9.3 to 1.9.3+ (build 20090114) i've got this error after the update : Notice: Undefined property: stdClass::$id in /moodle/lib/accesslib.php on line 4727 i read your report but don't understand what i have to do to fix this bug ... please can you tell me more ? thanks
Hide
Helen Foster added a comment -

Muriel, the simplest way to fix your problem would be to update to the latest stable version of Moodle 1.9.3+ from http://download.moodle.org/

Howard, thanks for reporting this issue and Tim, thanks for fixing it.

Show
Helen Foster added a comment - Muriel, the simplest way to fix your problem would be to update to the latest stable version of Moodle 1.9.3+ from http://download.moodle.org/ Howard, thanks for reporting this issue and Tim, thanks for fixing it.

People

Vote (0)
Watch (3)

Dates

  • Created:
    Updated:
    Resolved: