Come for the code, stay for the community

Development taxonomy term has incorrect id in title

Context

Sometimes entities created in a reference field get an incorrect ID.

Example: This term has (48) in the title:
https://contrib.drupalarchitect.info/drupal/development-48

This might be related to using Popular Tags, or this patch for referencing entities with parenthesis in the title.

This issue mentions the combination: https://www.drupal.org/project/drupal/issues/2924783#comment-14893268

The last comment has an explanation of the bug: https://www.drupal.org/project/drupal/issues/2924783#comment-16278176

Reproduction

With patch #46 in #2924783, referencing an entity with ID 48 is creating a new entity with (48) in the title.

Drupal Architect: https://www.drupalarchitect.info/tags/search-48

Contrib: https://contrib.drupalarchitect.info/drupal/development-48

Resolution

New patch should fix issues with handling ID numbers.

List all taxonomy terms to find parenthesis:
drush sqlq "select tid, name from taxonomy_term_field_data where name like '%(%' order by name"

List all node titles with parenthesis:
drush sqlq "select nid, title from node_field_data where title like '%(%' order by title"

TODO

Point duplicate references back to original, delete duplicate.

Modules
Task type