Moodle
  1. Moodle
  2. MDL-24086

Error reading from database when user bulk action or browse

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 2.0
    • Fix Version/s: None
    • Component/s: Administration
    • Labels:
      None
    • Environment:
      Ubuntu 10.04 server
    • Database:
      MySQL
    • Affected Branches:
      MOODLE_20_STABLE
    • Rank:
      2714

      Description

      Using moodle 2.0 preview 4 (build 20100829)

      I went to administration -> users -> accounts -> bulk user actions

      I wanted to enroll all students who were in one class into another class.

      I clicked advanced to filter users who were enrolled in the first class.

      And now it just gives an "Error reading from database" - even if I just click on the link
      to browse users, or if I click again on the link to bulk user actions.

      I enabled more verbose debugging and got these errors:

      Notice: Undefined variable: CFG in /var/www/moodle/admin/user/lib.php on line 28
      Notice: Trying to get property of non-object in /var/www/moodle/admin/user/lib.php on line 28
      Notice: Undefined variable: CFG in /var/www/moodle/admin/user/lib.php on line 30
      Notice: Trying to get property of non-object in /var/www/moodle/admin/user/lib.php on line 30
      

      and the developer debugging output when clicking bulk user actions:

      Debug info: Unknown column 'a.timestart' in 'where clause'
      SELECT COUNT('x') FROM mdl_user WHERE id<>? AND deleted <> 1 AND id IN (SELECT userid
      FROM mdl_role_assignments a
      INNER JOIN mdl_context b ON a.contextid=b.id
      INNER JOIN mdl_course c ON b.instanceid=c.id
      WHERE b.contextlevel=50 AND a.timestart<1283693769 AND (a.timeend=0 OR a.timeend>1283693769) AND c.category=2)
      [array (
      0 => NULL,
      )]
      Stack trace:
      
          line 391 of /lib/dml/moodle_database.php: dml_read_exception thrown
          line 732 of /lib/dml/mysqli_native_moodle_database.php: call to moodle_database->query_end()
          line 1237 of /lib/dml/moodle_database.php: call to mysqli_native_moodle_database->get_records_sql()
          line 1312 of /lib/dml/moodle_database.php: call to moodle_database->get_record_sql()
          line 1483 of /lib/dml/moodle_database.php: call to moodle_database->get_field_sql()
          line 1466 of /lib/dml/moodle_database.php: call to moodle_database->count_records_sql()
          line 31 of /admin/user/lib.php: call to moodle_database->count_records_select()
          line 32 of /admin/user/user_bulk.php: call to get_selection_data()
      
      

        Issue Links

          Activity

          Hide
          Doug Holton added a comment -

          I guess it may have been related to having an empty role ('any role') in the filter.

          I logged out and logged back in and can see the users again.

          The notices about the CFG variable are still there when I click bulk user actions, but it appears non-fatal.

          Show
          Doug Holton added a comment - I guess it may have been related to having an empty role ('any role') in the filter. I logged out and logged back in and can see the users again. The notices about the CFG variable are still there when I click bulk user actions, but it appears non-fatal.
          Hide
          Adam Olley added a comment -

          This is definitely an issue with filtering by role and affects the normal 'Browse list of users' as well as the bulk user actions.

          Steps to replicate:
          1) Go to Browse List of Users
          2) Use the advanced button to bring up the advanced filter options
          3) Change the 'system role' pull-down to Manager (or any other system role)
          4) Click the Add Filter button
          And you're presented with the error shown in the original description.

          It's trying to pull a non-existent 'timestart' column from role_assignments and so errors out.

          Show
          Adam Olley added a comment - This is definitely an issue with filtering by role and affects the normal 'Browse list of users' as well as the bulk user actions. Steps to replicate: 1) Go to Browse List of Users 2) Use the advanced button to bring up the advanced filter options 3) Change the 'system role' pull-down to Manager (or any other system role) 4) Click the Add Filter button And you're presented with the error shown in the original description. It's trying to pull a non-existent 'timestart' column from role_assignments and so errors out.
          Hide
          Adam Olley added a comment -
          Unable to find source-code formatter for language: php. Available languages are: actionscript, html, java, javascript, none, sql, xhtml, xml
           
          --- a/user/filters/globalrole.php
          +++ b/user/filters/globalrole.php
          @@ -66,8 +66,7 @@ class user_filter_globalrole extends user_filter_type {
           
                   $sql = "id IN (SELECT userid
                                    FROM {role_assignments} a
          -                        WHERE a.contextid=".SYSCONTEXTID." AND a.roleid=$value AND a.timestart<$timenow
          -                              AND (a.timeend=0 OR a.timeend>$timenow))";
          +                        WHERE a.contextid=".SYSCONTEXTID.")";
                   return array($sql, array());
               }
          

          Fixes this since role_assignments no longer have a start or end time.

          Show
          Adam Olley added a comment - Unable to find source-code formatter for language: php. Available languages are: actionscript, html, java, javascript, none, sql, xhtml, xml --- a/user/filters/globalrole.php +++ b/user/filters/globalrole.php @@ -66,8 +66,7 @@ class user_filter_globalrole extends user_filter_type { $sql = "id IN (SELECT userid FROM {role_assignments} a - WHERE a.contextid= ".SYSCONTEXTID." AND a.roleid=$value AND a.timestart<$timenow - AND (a.timeend=0 OR a.timeend>$timenow))"; + WHERE a.contextid= ".SYSCONTEXTID." )"; return array($sql, array()); } Fixes this since role_assignments no longer have a start or end time.
          Hide
          Adam Olley added a comment -

          Just noticed the 'fix' in my comment has the roleid missing "AND a.roleid=$value". Which is obviously needed to filter by role types.

          Show
          Adam Olley added a comment - Just noticed the 'fix' in my comment has the roleid missing "AND a.roleid=$value". Which is obviously needed to filter by role types.
          Hide
          Dan Poltawski added a comment -

          Thanks for the report, and sorry that nobody had looked at it before! I've just fixed the problem in MDL-25657

          Show
          Dan Poltawski added a comment - Thanks for the report, and sorry that nobody had looked at it before! I've just fixed the problem in MDL-25657

            People

            • Votes:
              1 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: