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 ё.