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

get_role_users() fails with specific fields on PostgreSQL

XMLWordPrintable

    • PostgreSQL
    • MOODLE_30_STABLE
    • MOODLE_31_STABLE
    • MDL_52574_master
    • Hide

      (difficulty: medium, requires a Moodle installation with PHPUnit installed and PostgreSQL)
      1. Navigate to the Moodle root directory
      2. From a terminal execute

      php vendor/bin/phpunit lib/tests/accesslib_test.php

      The test should pass if the patch works correctly.

      Show
      (difficulty: medium, requires a Moodle installation with PHPUnit installed and PostgreSQL) 1. Navigate to the Moodle root directory 2. From a terminal execute php vendor/bin/phpunit lib/tests/accesslib_test.php The test should pass if the patch works correctly.

      get_role_users(), without a $sort argument, fails on PostgreSQL when requesting fields that are absent from the default value for the $sort argument.

      The default value for the $sort argument (when it is missing from the function call) is returned by the function users_order_by_sql('u') and it is 'u.lastname,u.firstname,u.id'. If any of these fields are missing from the $fields argument for the get_role_users() function call then a dmlreadexception is thrown.

      You can paste the following code snipped in a file located in the moodle root directory to replicate the issue:

      <?php
      define('CLI_SCRIPT', true);
       
      require(__DIR__ . '/config.php');
      require_once($CFG->libdir . '/moodlelib.php');
      require_once($CFG->libdir . '/coursecatlib.php');
       
      $courses = get_courses();
      // Get the context from the first course in the list, the actual courses doesn't matter.
      $firstcoursecontext = context_course::instance(reset($courses)->id);
      $roles = get_all_roles();
      // Get the role id for the first role in the role list, the actual role doesn't matter.
      $firstroleid = reset($roles)->id;
      $userfields = 'u.firstname';
       
      $usersassigned = get_role_users($firstroleid, $firstcoursecontext, false, $userfields);
      echo "no exception thrown\n";
      

      The snippet should print 'no exception thrown', instead I get a dmlreadexception.

      I am using PostgreSQL version 9.2.14 on centos7.

            alexandru.elisei Alexandru Elisei
            alexandru.elisei Alexandru Elisei
            David Mudrák (@mudrd8mz) David Mudrák (@mudrd8mz)
            Andrew Lyons Andrew Lyons
            Simey Lameze Simey Lameze
            Votes:
            1 Vote for this issue
            Watchers:
            8 Start watching this issue

              Created:
              Updated:
              Resolved:

                Error rendering 'clockify-timesheets-time-tracking-reports:timer-sidebar'. Please contact your Jira administrators.