When you install a module that changes the field storage definitions and also change the entity type definitions (I do this with Multiversion module), the update process fails with these errors:
Drupal\Core\Database\SchemaObjectDoesNotExistException: Cannot add field entity_test_field_override_revision._deleted: table doesn't exist. in Drupal\Core\Database\Driver\mysql\Schema->addField() (line 328 of .../core/lib/Drupal/Core/Database/Driver/mysql/Schema.php).
or
Drupal\Core\Database\SchemaObjectExistsException: Cannot add field entity_test_field_override._deleted: field already exists. in Drupal\Core\Database\Driver\mysql\Schema->addField() (line 331 of .../core/lib/Drupal/Core/Database/Driver/mysql/Schema.php).
| Comment | File | Size | Author |
|---|---|---|---|
| #19 | 2398689-19-fix-entity-type-update.patch | 7.9 KB | jeqq |
| #19 | interdiff-16-19.txt | 2.67 KB | jeqq |
| #16 | 2398689-16-fix-entity-type-update.patch | 7.23 KB | jeqq |
Comments
Comment #1
jeqq commentedComment #2
amateescu commentedWasn't #2342543: Applying entity schema updates fail when both entity type and base field definitions change at the same time supposed to fix this?
Comment #3
berdirYes, it was, are you sure you tested with latest dev snapshot and not a beta?
Comment #4
jeqq commented@Berdir, I tested with latest dev snapshot. Steps to reproduce:
hook_entity_type_alter():hook_entity_base_field_info()for the same entity type.In this case firstly we need to update the entity type storage (will create the [entity-type-id]_revision table) and then to create the new fields. At the moment in
EntityDefinitionUpdateManager::applyUpdates()theEntityManager::onFieldStorageDefinitionCreate()method is executed beforeEntityManager::onEntityTypeUpdate()and the [entity-type-id]_revision table doesn't exist.Comment #5
plachComment #6
jeqq commentedThis can be reproduced when you make the entity revisionable and add a new revisionable field. I've created a failing test that demonstrates this.
Comment #7
jeqq commentedComment #9
jeqq commentedReroll
Comment #10
jeqq commentedComment #12
jeqq commentedMoved the entity type update before field storage definition creation to ensure that the revision table will be created before revisionable fields.
Comment #13
dixon_I would almost want to bump this to critical considering that #2342543: Applying entity schema updates fail when both entity type and base field definitions change at the same time was critical and the issue isn't fully resolved yet. But I'll leave it up to someone else to decide on that. I'm changing the title though to make it clear that this closely related to the original issue.
I think it would be good to add a comment to each of these three sections, saying something like "The table/field/index might already have been created as part of the earlier entity type update event."
Let's change the description to "A new revisionable base field"
Comment #14
jeqq commentedAdded comments and fixed the label.
Comment #15
dixon_Minor nit-pick - let's also wrap this comment line at 80 characters.
Comment #16
jeqq commentedThanks for the review @dixon_.
Comment #17
dixon_Thanks @jeqq! IMO this one is ready.
Comment #18
plachLooks great, thanks, only a couple of minor issues:
These need to be a single line shorter than 80 chars. Let's add a one-line intro followed by a blank line and put the rest in a following paragraph if needed.
Can we use a
$messagevariable to avoid replicating the text?Comment #19
jeqq commentedThanks @plach!
Comment #20
jeqq commentedComment #21
jeqq commentedComment #22
plachBack to RTBC
Comment #23
plachComment #24
alexpottThis issue addresses a major bug and is allowed per https://www.drupal.org/core/beta-changes. Committed d42d61a and pushed to 8.0.x. Thanks!