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

Fatal error when adding a tag string that is different in PHP but the same for DB

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Open
    • Priority: Major
    • Resolution: Unresolved
    • Affects Version/s: 3.9.1
    • Fix Version/s: None
    • Component/s: Tags
    • Labels:
    • Affected Branches:
      MOODLE_39_STABLE

      Description

      We found this issue while improving External Database Enrolment plugging to create course tags.

      To reproduce using MySQL: 

      1) Add a course tag containing cyrillic character ё for example, "Мёд"

      2) Add to another course the same tag replacing ё with е c.f. "Мед" (MySQL utf8 considers е and ё the same character)

      Fatal error like this

      Duplicate entry '1-мед' for key 'mdl_tag_tagnam_uix'
      INSERT INTO mdl_tag (isstandard,userid,timemodified,tagcollid,rawname,name) VALUES(?,?,?,?,?,?)
      [array (
      0 => 0,
      1 => '2',
      2 => 1599822719,
      3 => '1',
      4 => 'Мед',
      5 => 'мед',
      )]
      Error code: dmlwriteexception

      Stack trace:

      • line 489 of /lib/dml/moodle_database.php: dml_write_exception thrown
      • line 1357 of /lib/dml/mysqli_native_moodle_database.php: call to moodle_database->query_end()
      • line 1403 of /lib/dml/mysqli_native_moodle_database.php: call to mysqli_native_moodle_database->insert_record_raw()
      • line 180 of /tag/classes/tag.php: call to mysqli_native_moodle_database->insert_record()
      • line 369 of /tag/classes/tag.php: call to core_tag_tag::add()
      • line 772 of /tag/classes/tag.php: call to core_tag_tag::create_if_missing()
      • line 2587 of /course/lib.php: call to core_tag_tag::set_item_tags()
      • line 193 of /course/edit.php: call to update_course()

      The bug is reproducible on https://sandbox.moodledemo.net/

      It seems the new tag is considered missing in core_tag_tag::create_if_missing() because for PHP the strings are different, but for MySQL they are the same that causes the key constraint to fail.

      This may affect more pairs of characters than е and ё. 

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              Unassigned Unassigned
              Reporter:
              oa_sychev Oleg Sychev
              Participants:
              Component watchers:
              Amaia Anabitarte, Carlos Escobedo, Ferran Recio, Sara Arjona (@sarjona)
              Votes:
              1 Vote for this issue
              Watchers:
              3 Start watching this issue

                Dates

                Created:
                Updated: