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

Error when updating choice with multiple options and limits set

    Details

    • Type: Bug
    • Status: Open
    • Priority: Minor
    • Resolution: Unresolved
    • Affects Version/s: 3.1.2
    • Fix Version/s: None
    • Component/s: Choice
    • Labels:
      None
    • Affected Branches:
      MOODLE_31_STABLE

      Description

      Steps to reproduce:

      1. Create a choice activity with Allow choice to be updated = Yes; Allow more than one choice to be selected = Yes; Limit the number of responses allowed = Yes
      2. Create two options, each limited to two users
      3. User 1 selects option 1 and saves their choice
      4. User 2 selects both options and saves their choice; option 1 has now reached its limit
      5. User 1 attempts to add option 2 to their existing choice, but when they click Save my choice, they receive the error 'The choice is full and there are no available places' (see attached screenshot)

      Alternatively:

      1. User 1 selects option 1 and saves their choice
      2. User 2 selects both options and saves their choice; option 1 has now reached its limit
      3. User 2 attempts to remove option 2 from their existing choice, and receives the same error as above

      Expected result (in both cases):
      Users can always update their choices when doing so will not take any individual option over its limit.

      The cause appears to be that $choicesexceeded is set to a single true/false value for the whole Choice activity, not on a per-option basis. The way in which this is done does not take account of the user's existing selection, so the result in the above scenarios is $choicesexceeded=true and the user gets a 'choice is full' error message

      See choice_user_submit_response in moodle/mod/choice/lib.php:

              foreach ($countanswers as $opt => $count) {
                  if ($count >= $choice->maxanswers[$opt]) {
                      $choicesexceeded = true;
                      break;
                  }
              }
      

      Then:

          if (!($choice->limitanswers && $choicesexceeded)) {
      

      Which in both above scenarios prints the error message:

          } else {
              // Check to see if current choice already selected - if not display error.
              $currentids = array_keys($current);
       
              if (array_diff($currentids, $formanswers) || array_diff($formanswers, $currentids) ) {
                  // Release lock before error.
                  $choicelock->release();
                  print_error('choicefull', 'choice', $continueurl);
              }
          }
      

      https://tracker.moodle.org/browse/MDL-53459 and https://tracker.moodle.org/browse/MDL-51606 can produce the same result, but the issue here is distinct from the database lock issue. It may be the same issue as https://tracker.moodle.org/browse/MDL-52967.

        Gliffy Diagrams

          Attachments

            Activity

              People

              • Assignee:
                Unassigned
                Reporter:
                ericabithell Erica Bithell
                Participants:
                Component watchers:
                Dan Marsden, Jake Dallimore, Jun Pataleta
              • Votes:
                2 Vote for this issue
                Watchers:
                3 Start watching this issue

                Dates

                • Created:
                  Updated: