Uploaded image for project: 'Moodle'
  1. Moodle
  2. MDL-68727

Error reading from database when viewing students grades

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Open
    • Priority: Minor
    • Resolution: Unresolved
    • Affects Version/s: 3.8.3
    • Fix Version/s: None
    • Component/s: Blocks
    • Affected Branches:
      MOODLE_38_STABLE

      Description

      To reproduce the mentioned behavior:

      You need a course with seperate groups and force group mode enabled.

      You need to activate the "Users Online"-Block on all pages, so its also displayed when visiting "participants" of the course.

      Create a teacher and some student and enrol them to the course. Also assign the teacher to the students as a mentor (easy with Site-Administration -> Users -> Assign user roles to cohort)

      Login as teacher and visit the course. Go to participants and choose one of the students so you see his/her profile. You should see "Grade" at the very bottom of the "Reports"-section.

      When you click it you get a database error:

      // Error reading from database:
      Debug info: Unknown column 'u.id' in 'on clause'
      SELECT COUNT(u.id)
      FROM mdl_user u , mdl_groups_members gm
      LEFT JOIN mdl_user_preferences up ON up.userid = u.id
      AND up.name = 'block_online_users_uservisibility' 
      WHERE u.lastaccess > 1589459900.0
      AND u.lastaccess <= 1589460233
      AND u.deleted = 0
      AND ( CAST(up.value AS SIGNED) = 1
      OR up.value IS NULL
      OR u.id = '533')
      AND u.id = gm.userid AND gm.groupid = 551
      [array (
      0 => 'block_online_users_uservisibility',
      1 => 1589459900.0,
      2 => 1589460233,
      3 => '533',
      4 => 551,
      )]
      Error code: dmlreadexception
      Stack trace:
      line 486 of /lib/dml/moodle_database.php: dml_read_exception thrown
      line 1247 of /lib/dml/mysqli_native_moodle_database.php: call to moodle_database->query_end()
      line 1587 of /lib/dml/moodle_database.php: call to mysqli_native_moodle_database->get_records_sql()
      line 1660 of /lib/dml/moodle_database.php: call to moodle_database->get_record_sql()
      line 1870 of /lib/dml/moodle_database.php: call to moodle_database->get_field_sql()
      line 189 of /blocks/online_users/classes/fetcher.php: call to moodle_database->count_records_sql()
      line 80 of /blocks/online_users/block_online_users.php: call to block_online_users\fetcher->count_users()
      line 336 of /blocks/moodleblock.class.php: call to block_online_users->get_content()
      line 230 of /blocks/moodleblock.class.php: call to block_base->formatted_contents()
      line 1181 of /lib/blocklib.php: call to block_base->get_content_for_output()
      line 1233 of /lib/blocklib.php: call to block_manager->create_block_contents()
      line 374 of /lib/blocklib.php: call to block_manager->ensure_content_created()
      line 3920 of /lib/outputrenderers.php: call to block_manager->region_has_content()
      line 41 of /theme/eguru/layout/columns2.php: call to core_renderer->blocks()
      line 1374 of /lib/outputrenderers.php: call to include()
      line 1304 of /lib/outputrenderers.php: call to core_renderer->render_page_layout()
      line 1941 of /lib/setuplib.php: call to core_renderer->header()
      line 167 of /course/user.php: call to bootstrap_renderer->__call()
      
      

      Reason: The mysql-left-join statement is wrong. It is part of the "Users online"-Block (file /blocks/online_users/classes/fetcher.php)

      Fix: change the order of the tables in "FROM mdl_user u , mdl_groups_members gm" to "FROM mdl_groups_members gm, mdl_user u".

      There are two places where to change this. I have a patch ready and attached!

        Attachments

          Activity

            People

            Assignee:
            Unassigned Unassigned
            Reporter:
            Heinemann Jakob
            Participants:
            Component watchers:
            Adrian Greeve, Jake Dallimore, Mathew May, Mihail Geshoski, Peter Dias, Sujith Haridasan
            Votes:
            1 Vote for this issue
            Watchers:
            5 Start watching this issue

              Dates

              Created:
              Updated: