AO3-6811 Fix tag nomination parented bug#5845
Conversation
|
Assigning myself as reviewer since I saw some things I want to poke at, but I am beat so that's not gonna happen tonight |
sarken
left a comment
There was a problem hiding this comment.
Thanks for working on this! I've updated the Jira issue with new testing steps and just have one question about this code.
| # Calculate the parents associated with this tag, because we'll set any | ||
| # TagNominations with a matching parent_tagname to have parented: true. | ||
| parent_names = parents.where(type: "Fandom").pluck(:name) | ||
| parent_names = parents.pluck(:name) |
There was a problem hiding this comment.
I'm not sure this is necessary. A nomination's parent_tagname should always be the name of a fandom unless the nominated tag itself is a fandom. For fandom nominations, it seems like the parent_tagname is always nil, never the name of a media tag. I took a look at staging to confirm:
3.4.6 :001 > noms = FandomNomination.where("parent_tagname IS NOT NULL") ; nil
=> nil
3.4.6 :002 > noms.size
=> 0
3.4.6 :003 > noms = FandomNomination.where(parent_tagname: "") ; nil
=> nil
3.4.6 :004 > noms.size
=> 0
3.4.6 :005 > noms = FandomNomination.where(parent_tagname: nil) ; nil
=> nil
3.4.6 :006 > noms.size
=> 21488
3.4.6 :007 > FandomNomination.all.count
=> 21488Can you think of a scenario in which we'd expect to find a tag nomination with a non-fandom, non-blank, and non-nil parent_tagname?
There was a problem hiding this comment.
You're right that fandom nominations always have parent_tagname: nil and the media parent name itself won't directly match any nomination. But after digging deeper, I think removing the type filter is still needed, looking at https://github.com/otwcode/otwarchive/blob/master/app/models/fandom.rb#L44 a Fandom's parent_types are either Media or MetaTag which means parents.where(type: "Fandom") would always return [] for any fandom tag. So parent_names.present? would always be false, nil would never get added, and the update_all would match nothing, leaving the nominations as parented: false
I admit the fix is a bit indirect though, the media parent names in the list won't match anything, but they make parent_names non-empty so that nil gets added on line 1259, which is what actually matches the fandom nominations.
Maybe this would be a cleaner approach.
if canonical? && parents.exists?
parent_names = parents.where(type: "Fandom").pluck(:name).push("", nil)
TagNomination.where(tagname: name, parent_tagname: parent_names).update_all(parented: true)
end
@sarken thanks for you review! Let me know your thoughts
Pull Request Checklist
AO3-1234 Fix thing)Issue
https://otwarchive.atlassian.net/browse/AO3-6811
Purpose
When a canonical tag is saved,
Tag#update_tag_nominationssetsparented: trueon matchingTagNominationrecords.However, it only checked for
Fandom-type parents and only matched nominations with a blankparent_tagname(empty string).This caused nominations to be incorrectly marked as
parented: falsewhen:nilparent_tagnameinstead of an empty string.This PR fixes both issues by:
""andnilin theparent_nameslist so nominations with either blank value are matched.Testing Instructions
parentedfield istrue.Credit
Pablo Monfort (he/him)