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

An extra question field cannot be set back to null when saving a question

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Minor
    • Resolution: Fixed
    • Affects Version/s: 2.4
    • Fix Version/s: 2.3.5, 2.4.2
    • Component/s: Questions
    • Labels:
    • Testing Instructions:
      Hide

      Of the core question types, only shortanswer uses this feature. If you have any contrib question types installed, then it would be good to test them too. Please test:
      1. Create new question.
      2. Edit question.
      3. Preview question.
      4. Export / Import questions as Moodle XML.

      Show
      Of the core question types, only shortanswer uses this feature. If you have any contrib question types installed, then it would be good to test them too. Please test: 1. Create new question. 2. Edit question. 3. Preview question. 4. Export / Import questions as Moodle XML.
    • Affected Branches:
      MOODLE_24_STABLE
    • Fixed Branches:
      MOODLE_23_STABLE, MOODLE_24_STABLE
    • Pull from Repository:
    • Pull Master Branch:

      Description

      questiontypebase.php does not allow setting a question option field to null. To reproduce:

      1. Define in the xml a question_blah_options field x, say, with NOTNULL false.
      2. Call qtype_blah.save_question_options($q) with $q.x set to some non-null value.
      3. Now try to resave the question with $q.x set to null.

      The code in questiontypebase.save_question_options will give an error around line 457 due to the test "if (!isset($question->$field))". The error probably goes undetected because the return value of the function cannot meaningfully be checked as it's not always defined. Instead the call to save the question options silently aborts.

      Fix: change the test in line 457 (or thereabouts) to

      if (!property_exists($question, $field))

      Also, would it be safer to throw a coding_exception if this condition occurs rather than silently aborting the execution?

        Gliffy Diagrams

          Attachments

            Activity

              People

              • Votes:
                0 Vote for this issue
                Watchers:
                7 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:
                  Fix Release Date:
                  11/Mar/13