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

Authentication plugins produce config_plugin settings with names that are way too long and break upgrades

XMLWordPrintable

    • MOODLE_34_STABLE
    • MOODLE_33_STABLE, MOODLE_34_STABLE
    • wip-MDL-60926-master
    • Hide

      This change affects all authentication types with external synchronizations. Following testing instructions are for auth_db as it is the easiest to set up. Feel free to use other auth methods instead (LDAP, CAS, Shibboleth)

      1. Create two custom user profie fields (textfield), one with short name exactly 67 characters long, another one with short name at least 68 characters long (it allows up to 255).
      2. Bump version in version.php and run site upgrade - there should be no errors
      3. create database table somewhere with fields id, username, password, email, customfield (or more fields if you want), add one user there
      4. Set up authentication plugin auth_db pointing to this table, specify field names for username, password, email
      5. On "Manage authentication plugins" page test settings for auth_db, they should be ok
      6. Go to the plugin settings again. Set up mapping between the field that is 67 chars long and the 'customfield' in external db (both local and remote)
      7. Make sure that the second field (that is >=68 chars long) appears as "unable to map"
      8. Go to scheduled tasks page, enable and run scheduled task for auth_db
      9. Go to Site administration>Users>Browse list of users and make sure the new user was inserted ....
      10. Edit their profile and make sure the first custom field was imported...
      11. Ah! It was not! Congratulations, you just reproduced MDL-56093 ! (Maybe you can fix it too while you are here?)
      12. Edit user in moodle, change the value of the first custom field
      13. Run scheduled task for auth_db again
      14. Check in the external database that the custom profile field was updated for the user
      Show
      This change affects all authentication types with external synchronizations. Following testing instructions are for auth_db as it is the easiest to set up. Feel free to use other auth methods instead (LDAP, CAS, Shibboleth) Create two custom user profie fields (textfield), one with short name exactly 67 characters long, another one with short name at least 68 characters long (it allows up to 255). Bump version in version.php and run site upgrade - there should be no errors create database table somewhere with fields id, username, password, email, customfield (or more fields if you want), add one user there Set up authentication plugin auth_db pointing to this table, specify field names for username, password, email On "Manage authentication plugins" page test settings for auth_db, they should be ok Go to the plugin settings again. Set up mapping between the field that is 67 chars long and the 'customfield' in external db (both local and remote) Make sure that the second field (that is >=68 chars long) appears as "unable to map" Go to scheduled tasks page, enable and run scheduled task for auth_db Go to Site administration>Users>Browse list of users and make sure the new user was inserted .... Edit their profile and make sure the first custom field was imported... Ah! It was not! Congratulations, you just reproduced MDL-56093 ! (Maybe you can fix it too while you are here?) Edit user in moodle, change the value of the first custom field Run scheduled task for auth_db again Check in the external database that the custom profile field was updated for the user

      To reproduce:

      1. Install a 33 site
      2. Add a custom user profile field with a 100 character long identifier (the max that the UI permits), I used "ReallyLongFieldIdentifierReallyLongFieldIdentifierReallyLongFieldIdentifierReallyLongFieldIdentifier"
      3. Checkout the 34 codebase and run the upgrade
      4. At the end of the upgrade you see something like:

      Default exception handler: Error writing to database Debug: ERROR:  value too long for type character varying(100)
      INSERT INTO mdl_config_plugins (plugin,name,value) VALUES($1,$2,$3)
      [array (
        'plugin' => 'auth_cas',
        'name' => 'field_map_profile_field_ReallyLongFieldIdentifierReallyLongFieldIdentifierReallyLongFieldIdentifierReallyLongFieldIdentifier',
        'value' => '',
      )]
      Error code: dmlwriteexception
      * line 489 of /lib/dml/moodle_database.php: dml_write_exception thrown
      * line 242 of /lib/dml/pgsql_native_moodle_database.php: call to moodle_database->query_end()
      * line 886 of /lib/dml/pgsql_native_moodle_database.php: call to pgsql_native_moodle_database->query_end()
      * line 934 of /lib/dml/pgsql_native_moodle_database.php: call to pgsql_native_moodle_database->insert_record_raw()
      * line 1429 of /lib/moodlelib.php: call to pgsql_native_moodle_database->insert_record()
      * line 1781 of /lib/adminlib.php: call to set_config()
      * line 2181 of /lib/adminlib.php: call to admin_setting->config_write()
      * line 8041 of /lib/adminlib.php: call to admin_setting_configtext->write_setting()
      * line 8027 of /lib/adminlib.php: call to admin_apply_default_settings()
      * line 8027 of /lib/adminlib.php: call to admin_apply_default_settings()
      * line 8027 of /lib/adminlib.php: call to admin_apply_default_settings()
      * line 187 of /admin/cli/upgrade.php: call to admin_apply_default_settings()
       
      !!! Error writing to database !!!
      !! ERROR:  value too long for type character varying(100)
      INSERT INTO mdl_config_plugins (plugin,name,value) VALUES($1,$2,$3)
      [array (
        'plugin' => 'auth_cas',
        'name' => 'field_map_profile_field_ReallyLongFieldIdentifierReallyLongFieldIdentifierReallyLongFieldIdentifierReallyLongFieldIdentifier',
        'value' => '',
      )]
      Error code: dmlwriteexception !!
      !! Stack trace: * line 489 of /lib/dml/moodle_database.php: dml_write_exception thrown
      * line 242 of /lib/dml/pgsql_native_moodle_database.php: call to moodle_database->query_end()
      * line 886 of /lib/dml/pgsql_native_moodle_database.php: call to pgsql_native_moodle_database->query_end()
      * line 934 of /lib/dml/pgsql_native_moodle_database.php: call to pgsql_native_moodle_database->insert_record_raw()
      * line 1429 of /lib/moodlelib.php: call to pgsql_native_moodle_database->insert_record()
      * line 1781 of /lib/adminlib.php: call to set_config()
      * line 2181 of /lib/adminlib.php: call to admin_setting->config_write()
      * line 8041 of /lib/adminlib.php: call to admin_setting_configtext->write_setting()
      * line 8027 of /lib/adminlib.php: call to admin_apply_default_settings()
      * line 8027 of /lib/adminlib.php: call to admin_apply_default_settings()
      * line 8027 of /lib/adminlib.php: call to admin_apply_default_settings()
      * line 187 of /admin/cli/upgrade.php: call to admin_apply_default_settings()
       !!
      

      Seems like auth plugins prepend some extra text at the beginning of the field name which violates the 100 character constraint in the database.

            marina Marina Glancy
            cameron1729 cameron1729
            cameron1729 cameron1729
            Jun Pataleta Jun Pataleta
            David Mudrák (@mudrd8mz) David Mudrák (@mudrd8mz)
            Votes:
            0 Vote for this issue
            Watchers:
            7 Start watching this issue

              Created:
              Updated:
              Resolved:

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