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

Cannot edit courses when unique custom text fields are present

XMLWordPrintable

    • MOODLE_401_STABLE, MOODLE_402_STABLE, MOODLE_403_STABLE
    • MOODLE_401_STABLE, MOODLE_402_STABLE, MOODLE_403_STABLE
    • MDL-79365-401
    • MDL-79365-403
    • Hide
      1. Log in as admin
      2. Navigate to Courses > Course custom fields in site administration
      3. Add a new category (if none exists)
      4. Add a new Text area field
        • Name: Unique textarea
        • Shortname ufield
        • Unique data: Yes
      5. Create a new course
        • Fill in required fields
        • Unique textarea: Hello
      6. Save the course
      7. Confirm there are no form errors
      8. Add another new course:
        • Fill in required fields
        • Leave the Unique textarea field blank
      9. Save the course
      10. Confirm there are no form errors
      11. Add another new course
        • Fill in required fields
        • Leave the Unique textarea field blank
      12. Save the course
      13. Confirm there are no form errors
      14. Edit the course settings
        • Unique textarea: Hello
      15. Save the course
      16. Confirm you see the error "This value is already used." for your custom field
      17. Change Unique textarea to "Goodbye"
      18. Save the course
      19. Confirm there are no form errors
      Show
      Log in as admin Navigate to Courses > Course custom fields in site administration Add a new category (if none exists) Add a new Text area field Name: Unique textarea Shortname ufield Unique data: Yes Create a new course Fill in required fields Unique textarea: Hello Save the course Confirm there are no form errors Add another new course: Fill in required fields Leave the Unique textarea field blank Save the course Confirm there are no form errors Add another new course Fill in required fields Leave the Unique textarea field blank Save the course Confirm there are no form errors Edit the course settings Unique textarea: Hello Save the course Confirm you see the error "This value is already used." for your custom field Change Unique textarea to "Goodbye" Save the course Confirm there are no form errors

      When a site is configured with a custom field for courses of type `text area` - and set to be unique - courses can no longer be edited.

       

      With postgres, this results in:

      Warning: Array to string conversion in customfield/classes/data_controller.php on line 228
      array ( 0 => 1, 1 => array ( 'text' => 'testdata', 'format' => '1', 'itemid' => 659010097, ), 2 => 1, ) 

       

      When using mysql/mariadb this causes a more fatal error:

      Exception - mysqli::real_escape_string(): Argument #1 ($string) must be of type string, array given
       
      Stack trace:
      line 1149 of /lib/dml/mysqli_native_moodle_database.php: TypeError thrown
      line 1149 of /lib/dml/mysqli_native_moodle_database.php: call to mysqli->real_escape_string()
      line 1216 of /lib/dml/mysqli_native_moodle_database.php: call to mysqli_native_moodle_database->emulate_bound_params()
      line 2010 of /lib/dml/moodle_database.php: call to mysqli_native_moodle_database->get_recordset_sql()
      line 1995 of /lib/dml/moodle_database.php: call to moodle_database->record_exists_sql()
      line 248 of /customfield/classes/data_controller.php: call to moodle_database->record_exists_select()
      line 263 of /customfield/classes/data_controller.php: call to core_customfield\data_controller->is_unique()
      line 612 of /customfield/classes/handler.php: call to core_customfield\data_controller->instance_form_validation()
      line 502 of /course/edit_form.php: call to core_customfield\handler->instance_form_validation()
      line 653 of /lib/formslib.php: call to course_edit_form->validation()
      line 589 of /lib/formslib.php: call to moodleform->validate_defined_fields()
      line 699 of /lib/formslib.php: call to moodleform->is_validated()
      line 163 of /course/edit.php: call to moodleform->get_data()

       

       

            pholden Paul Holden
            aolley Adam Olley
            Carlos Escobedo Carlos Escobedo
            Ilya Tregubov Ilya Tregubov
            Kim Jared Lucas Kim Jared Lucas
            Votes:
            0 Vote for this issue
            Watchers:
            11 Start watching this issue

              Created:
              Updated:
              Resolved:

                Estimated:
                Original Estimate - 0 minutes
                0m
                Remaining:
                Remaining Estimate - 0 minutes
                0m
                Logged:
                Time Spent - 1 hour, 30 minutes
                1h 30m

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