When a work is deleted around the time that it's being reindexed, the indexing code will sometimes load the work, but not be able to find its stat counter. (They're both deleted in the same transaction, but the indexing code loads the work first, and then tries to find its stat counter later.) This results in a NoMethodError when calling comments_count, kudos_count, and bookmarks_count, all of which expect the stat_counter to exist, and all of which are included in the work's JSON document.
This error causes all other works in the same batch to fail to be indexed, which may contribute to AO3-5290.
Testing Instructions: This is an intermittent bug, so I'm not sure it can be consistently replicated. Probably the best policy with this is to deploy it, and check Resque a few days later to see if the error is still happening.
Setting to PAOB: we’ll check https://archiveofourown.org/resque/failed/?class=AsyncIndexer once this fix is deployed. There are a lot of errors there thanks to AO3-6066, so we might need to wait for that fix as well.
We cleared out all Resque failures on 2021-01-16 and waited a week. No such indexing errors reappeared so far. Looks good.