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

Incorrect usage of $DB->get_field() in core

    XMLWordPrintable

    Details

      Description

      There are a few places that incorrectly call $DB->get_field. The function only defines 4 params, but some places are calling it with 5, meaning the strictness param is lost, and meaning we don't always receive the exceptions when we should. E.g. (from question/type/multianswer/questiontype.php)

      $sequence = $DB->get_field('question_multianswer', 'sequence',
              array('question' => $question->id), '*', MUST_EXIST);

      Notice the erroneous ' * ' in there which in effect replaces the integer strictness param, meaning the function won't throw an exception if the record can't be found.

      The full list of those I've found in core via a quick grep (remember to consider multi-line function calls!):

      • enrol/imsenterprise/tests/imsenterprise_test.php
      • mod/assign/submission/file/locallib.php
      • mod/assign/submission/onlinetext/locallib.php
      • question/type/multianswer/questiontype.php
      • search/tests/behat/behat_search.php

      These incorrect usages should be fixed.

      Originally reported as:
      Call to DB->get_field in question/type/multianswer/questiontype.php get_question_options has MUST_EXIST argument, but no exception is thrown when there is no record in mdl_question_multianswer for specified question.

      This leads to breakage in a subsequent call from line 52 of /question/type/multianswer/questiontype.php to moodle_database->get_records_list() when trying to export question banks.

      Using Postgres 9.1 on Debian.

        Attachments

          Activity

            People

            Assignee:
            jaked Jake Dallimore
            Reporter:
            nwpotago Nick Phillips
            Peer reviewer:
            Mark Nelson
            Integrator:
            Damyon Wiese
            Tester:
            CiBoT
            Participants:
            Component watchers:
            Andrew Nicols, Jun Pataleta, Michael Hawkins, Shamim Rezaie, Simey Lameze
            Votes:
            1 Vote for this issue
            Watchers:
            4 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved:
              Fix Release Date:
              15/Jan/18