Tag connections are lost when canonical tags are synned, aka the Tag Drop bug

Description

Steps to reproduce

Log in as an admin. On the edit page of a canonical tag, use the "Synonym of" field to syn that canonical tag to another tag, existing or not. This bug is intermittent, so it may take several tries to trigger it.

What happens

Periodically, all the connections from the old canonical tag are not transferred to the new tag. This includes metatags, subtags, synonyms, and other child tags. It's most obvious with fandom and character tags, which tend to have a lot of child tags. With fandom tags, this results in all the child tags and synonyms appearing in the mass bins again, as they have lost their fandom connection.

What should happen

All tag connections from the canonical should be transferred to the tag it is synned to, whether that tag is newly created or existed before.

Because this bug does not always happen, testing should be conducted on many tags.

Activity

Show:
ticking instant
February 8, 2019, 2:37 PM

Setting syn_string= to a valid merger results in an async call to transfer the associations:

(Source)

However, that action also triggers another async call in a before_update hook in the Tag class:

(Source)

Since setting the synonym also sets canonical to false at the same time, as soon as the tag is saved this callback will queue up a call to remove_canonical_associations (which does exactly what you’d think).

So effectively you have dueling asynchronous function calls. If add_merger_associations acts first, the associations are transferred properly. If remove_canonical_associations acts first, the associations are deleted instead of transferring.

(The call to add_merger_associations is enqueued first, so technically it should be run first, if only by a narrow margin. But it also takes more time to run, so if both functions start at roughly same time, remove_canonical_associations is more likely to finish first.)

ticking instant
February 8, 2019, 7:17 PM

This can also result from stale data. The call to add_merger_associations only works if the merger can be read from the database at the beginning of add_merger_associations, but it’s added to the Resque queue before anything is even written to the database.

Tag Wrangler Chairs
May 11, 2020, 12:57 PM
Edited

Qem:

Tested with renaming/synning several fandom tags and a few relationships. All tag connections carried across. At the moment works and bookmarks did not yet carry across but 15 minutes may not be enough time. Will check again tomorrow.

ETA:

Confirming works and bookmarks now appear.

redsummernight
May 24, 2020, 2:14 AM
Edited

Tested a character tag: https://test.archiveofourown.org/tags/Ayanami%20Rei (canonical). 55 works, 31 bookmarked items. Connections:

  • Parents: Neon Genesis Evangelion, Neon Genesis Evangelion: Gakuen Datenroku | Campus Apocalypse

  • Syns: Ayanami Rei (mention)

  • Metatags: Rei

  • Child relationships: Ayanami Rei/Ikari Shinji, Ayanami Rei/Katsuragi Misato, Ayanami Rei/Nagisa Kaworu, Ayanami Rei/Souryuu Asuka Langley, Ayanami Rei/Suzuhara Touji, Ayanami Rei/Uzumaki Naruto, Nagisa Kaworu/Ayanami Rei

As an admin, synned to non-existent tag "Ayanami Rei (5618)".

  • "Ayanami Rei" retained its fandoms, gained a merger "Ayanami Rei (5618)", lost the other connections.

  • "Ayanami Rei (5618)" had all the old connections, plus a new syn "Ayanami Rei".

Waiting for works and bookmarks to be reindexed into the new tag...
ETA: ~15m later, all 55 works and 31 bookmarks showed up under "Ayanami Rei (5618)".

Looks good.

Assignee

ticking instant

Reporter

briar_pipe

Roadmap

Tag Wrangling

Priority

Medium

Affects versions

Fix versions

Components

BackEnd

Difficulty

Hard

Required Access Level

Admin

Milestone

Internal 0.9
Configure