In taxonomy_access_module_db_rewrite_sql, a static variable $taxonomy_access_sql_clause is used to save the first evaluation of the visible terms for the user. There is no mechanism for that cache to be invalidated if new terms are added or term_access or term_access_default change between requests. This can result in duplication of tags when multiple nodes are saved with a new tag, since the tag did not exist at the first evaluation, it is not visible for the duration of the request. So each node adds a new copy of the same tag name.

This issue manifest itself with image_upload when the image type has a tagged vocabulary and the user does not have "administer taxonomy" and inserts multiple images with a new tag.

Unfortunately, taxonomy_node_save does not call db_rewrite_sql when it inserts a new tag, so there is not a chance to invalidate the cache at that point. The workaround for my application, is to remove the static declaration and not cache at all.

MySQL 5.1, though, I do not believe it matters.

Comments

xjm’s picture

Status: Active » Closed (duplicate)

Thank you for the thorough description of the issue.

Am I correct in understanding that this is a freetag vocabulary?

See also:
#168709: Duplicate taxonomy terms inserted by freeform tagging. Fix included.
#198773: Free tag vocabularies do not respect TAC and may cause duplicate term insertion

xjm’s picture

Making the older issue a duplicate of this one instead of vice versa:
#219511: Duplicate terms creation allowed

xjm’s picture

Title: Caching in tac_db_rewrite_sql results in duplicate tags » Caching in tac_db_rewrite_sql results in duplicate tags for freetaging vocabularies
Status: Closed (duplicate) » Active
xjm’s picture

See also #202039: Content Taxonomy Autocomplete terms are created twice if role does not have "create" privs for the vocab. Note that disabling the caching in hook_db_rewrite_sql() does not fix the duplicate term insertion with the Content Taxonomy module.