Works cannot be edited due to missing creatorships, usually after transferring the work to a different account

Description

Occasionally, we hear from users who cannot edit their works. Some users report a 500 error. Others say when they try to save their edits with or without previewing, the page refreshes the Edit Work page. The URL in the browser bar is for the work, but the page they see is the Edit Work page, and the edits are not saved. (Note: this is consistent with other errors when posting, e.g. if you disable JavaScript and attempt to remove the work title. The difference is other errors have a useful error message.) Still others receive the following error:

Sorry! We couldn't save this work because:
translation missing: en.activerecord.errors.models.work.attributes.base.base

99 times out of 100, this turns out to be caused by the first chapter of the work (which can be a single or multi-chapter work) not having a Creatorship. The work generally does have a creatorship:

2.3.4 :010 > w = Work.find(000)
=> #<Work id: 000...
2.3.4 :011 > w.creatorships
=> #<ActiveRecord::Associations::CollectionProxy [#<Creatorship id: 61349501, creation_id: 000, creation_type: "Work", pseud_id: ...
2.3.4 :012 > w.chapters.first.creatorships
=> #<ActiveRecord::Associations::CollectionProxy []>

This often – but possibly not always – happens when the user has transferred the work to a different account. This is done by adding the second account as a co-creator and then removing the first creator.

One report (Zoho ticket 212046) specifically says this happened after mass editing multiple single-chapter fics to switch accounts. Could this be related to AO3-3915?

Notes

The changes in should prevent any further instances of missing creatorships. However, there will still be some existing works work missing creatorships.

When editing works with missing creatorships:

  1. If you press Preview and then Update to edit the work, it works fine, and silently fixes the broken creatorships.

  2. If you press Post Without Preview to edit the work, it will generate a pair of confusing error messages, but otherwise resolve itself:

Sorry! We couldn't save this work because:
* Chapters creatorships pseud has already been taken
* Invalid chapter: Chapter must have at least one creator.

Testing notes

A database admin will need to break some works' creatorships for this to be tested.

Assignee

ticking instant

Reporter

Sarken

Roadmap

Works

Priority

Medium

Affects versions

Fix versions

Components

BackEnd

Difficulty

Hard

Milestone

Internal 0.9
Configure