SerialWork after_destroy callback causes an error when the series is missing.


There's a draft that can't be deleted as a result of a SerialWork where the series was somehow deleted. It's not clear what caused this (possibly a race condition?), but it would be good to make sure that the SerialWork destroy callbacks can handle this case without throwing an error.

In order to test this, you need to delete a SerialWork with a missing series. The only way I know to do that is as follows:

  1. Create a work.

  2. Add a new series to that work.

  3. Find the ID for that series.

  4. Go into the rails console and call Series.find(id).delete.

  5. View the work, press the "Edit" button, and then press "Delete Work."


January 1, 2019, 9:05 AM

Posted with the new series

Delete the series from the console:

ao3app@test-app12:~/app/current$ bundle exec rails c

Loading staging environment (Rails

2.3.4 :001 > Series.find(63526).delete

=> #<Series id: 63526, created_at: "2019-01-01 08:49:25", updated_at: "2019-01-01 08:49:26", title: "AO3-5580 Test Series", summary: nil, series_notes: nil, hidden_by_admin: false, restricted: false, complete: false, summary_sanitizer_version: 0, series_notes_sanitizer_version: 0>

2.3.4 :002 > Series.find(63526)

ActiveRecord::RecordNotFound: Couldn't find Series with 'id'=63526

from (irb):2

Pressed Edit on the work and got a 500 error loading /o\
I think the problem is calling delete on the series (thus leaving the Serial Work) means it’s still trying to load the series info for the form.

Back in the console, if I call destroy on the work, it works:

2.3.4 :003 > Work.find(1068667).destroy

Dalli::Server#connect test-redis01:11211

UserMailer#delete_work_notification: processed outbound mail in 572.6ms

Sent mail to (63.7ms)

I got the email and could open the attachment and everything.

I’d say this solves the issue of drafts not being deletable when the series is missing from the SerialWork, but the steps to reproduce have brought to our attention a different problem with the work form. I’m not sure the 500 error is something we need to spend out time fixing, though: afaik, we’ve never had a work that couldn’t be edited due to a SerialWork with a missing Series. (Seems plausible given we only ran into one draft with the problem.)

If we make a new issue for that, I’d suggest marking it lowest priority.

Lady Oscar
January 9, 2019, 6:17 PM

Looks good!

If the editing error hasn't come up for real users by now (and I'm sure if someone had a work that was stuck like that we'd hear about it), it seems like we can probably leave it be.


ticking instant


ticking instant





Affects versions

Fix versions





Required Access Level



Internal 0.9