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

Error when updating choice with multiple options and limits set

    Details

    • Testing Instructions:
      Hide

      Editing an existing response (adding an option, or saving current options)

      1. As an admin/teacher, set up a choice with the following options set:
        • 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, Blue and Red. Limit Red to 2 and Blue to 1
      3. Make sure you have 2 students enrolled.
      4. Login as student 1 and select Blue and save. Blue has now reached its limit.
      5. Login as student 2 and select Red and save.
      6. Now, login as student 1 again, and add Red to your current selection and save.
      7. Verify you see the success notification. Now, both options are at their limits.
      8. Now, save the page again. Again verify you see the success message and no errors.
      9. Now, remove the Red option and save. Again verify you see the success message and no errors.

      Exceeding the limit for an option

      1. For both users click 'Remove my choice' and save. All limits are reset now.
      2. Now, you'll need two sessions for the next part, so open a new private window, or use another browser.
      3. In the first browser (student 1) open the choice and wait.
      4. In the second browser (student 2) open the choice and select Blue and save.
      5. Now, back in the first browser, select both options and save.
      6. Verify that you see the error notice stating "One or more of the options you have selected have already been filled. Your response has not been saved. Please make another selection"
      7. Continue and verify you are taken back to the choice page and that you now see the Blue option listed as 'Full'
      Show
      Editing an existing response (adding an option, or saving current options) As an admin/teacher, set up a choice with the following options set: Allow choice to be updated = Yes; Allow more than one choice to be selected = Yes; Limit the number of responses allowed = Yes Create two options, Blue and Red. Limit Red to 2 and Blue to 1 Make sure you have 2 students enrolled. Login as student 1 and select Blue and save. Blue has now reached its limit. Login as student 2 and select Red and save. Now, login as student 1 again, and add Red to your current selection and save. Verify you see the success notification. Now, both options are at their limits. Now, save the page again. Again verify you see the success message and no errors. Now, remove the Red option and save. Again verify you see the success message and no errors. Exceeding the limit for an option For both users click 'Remove my choice' and save. All limits are reset now. Now, you'll need two sessions for the next part, so open a new private window, or use another browser. In the first browser (student 1) open the choice and wait. In the second browser (student 2) open the choice and select Blue and save. Now, back in the first browser, select both options and save. Verify that you see the error notice stating "One or more of the options you have selected have already been filled. Your response has not been saved. Please make another selection" Continue and verify you are taken back to the choice page and that you now see the Blue option listed as 'Full'
    • Difficulty:
      Easy
    • Affected Branches:
      MOODLE_31_STABLE, MOODLE_34_STABLE, MOODLE_35_STABLE, MOODLE_36_STABLE
    • Fixed Branches:
      MOODLE_34_STABLE, MOODLE_35_STABLE
    • Pull from Repository:
    • Pull 3.4 Branch:
    • Pull 3.5 Branch:
    • Pull Master Branch:
      MDL-56881-master

      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

            Issue Links

              Activity

                People

                • Votes:
                  2 Vote for this issue
                  Watchers:
                  6 Start watching this issue

                  Dates

                  • Created:
                    Updated:
                    Resolved:
                    Fix Release Date:
                    10/Sep/18

                    Time Tracking

                    Estimated:
                    Original Estimate - 0 minutes
                    0m
                    Remaining:
                    Remaining Estimate - 0 minutes
                    0m
                    Logged:
                    Time Spent - 30 minutes
                    30m