Problem/Motivation
In our project we've been swapped out the taxonomy_term entity type storage. We are using a triplestore/SPARQL backend that is NOT extending from SqlContentEntityStorage, When taxonomy_post_update_make_taxonomy_term_revisionable() post update runs, it crashes with:
[notice] Update started: taxonomy_post_update_make_taxonomy_term_revisionable
[error] Exception thrown while performing a schema update. Cannot rename taxonomy_term__parent to old_taxonomy_term__parent: table taxonomy_term__parent doesn't exist.
[error] Update failed: taxonomy_post_update_make_taxonomy_term_revisionable
[error] Update aborted by: taxonomy_post_update_make_taxonomy_term_revisionable
[error] Finished performing updates.
We have this hook implementation:
function foo_entity_type_alter(array &$entity_types) {
$entity_types['taxonomy_term']->setStorageClass(CustomTermStorage::class);
}
The problem is that \Drupal::entityDefinitionUpdateManager()->getEntityType('taxonomy_term') returns the entity type definition without being altered by hook_entity_type_alter(). And that has the original TermStorage as storage class. Because TermStorage is instance of FieldStorageDefinitionListenerInterface will try to update the field storage but the tables don't exist as our term storage don't use MySQL tables.
Proposed resolution
TBD.
Remaining tasks
None.
User interface changes
None.
API changes
None.
Data model changes
None.
Release notes snippet
N/A
| Comment | File | Size | Author |
|---|---|---|---|
| #3 | 3048595-3.patch | 1.22 KB | claudiu.cristea |
Comments
Comment #2
claudiu.cristeaComment #3
claudiu.cristeaI cannot see other way.
But I'm still curious why
\Drupal::entityDefinitionUpdateManager()->getEntityType()doesn't alter the definition viahook_entity_type_alter().Comment #4
berdir\Drupal::entityDefinitionUpdateManager()->getEntityType() returns the "last installed entity type". All storage relevant changes need to be "installed" through update functions, I guess that includes switching out the storage handler entirely. See slack discussion in #contribute from today, was very related to that. And also https://www.drupal.org/node/3040966.
Comment #5
plachDefinitely, the fix should be installing the entity type update in a regular update function, so that the post update function will run with the intended storage class. Feel free to reopen if you still have a failure after doing that.
Comment #6
claudiu.cristeaThank you @Berdir, @plach. Indeed installing the entity type/field storages is fixing the issue. As I understand the entity query will use now the stored/installed definition rather than the one from code. Until now the entity type/field storage mismatch, revealed in the status report, was not a very big deal. But now it has impact. Shouldn't we emit some warning when using affected functionalities and there is mismatch in definitions?
Comment #7
plachDo you mean store some flag in state and raise a warning when instantiating the storage or something like along those lines?
Comment #8
claudiu.cristea@plach for example somebody is running an entity query for an entity type that has entity type/field storage misitymatches (i.e. the code changes are not installed). As I understand the entity query will use the installed entity type definition, rather than definition from code. I'm expecting that such an entity query to have wrong results. If this is true, shouldn't we trigger some error/warning message when such a query runs?
Comment #9
salihcenap commentedpatch did'nt work for me. Still cannot update..
Comment #10
amateescu commented@salihcenap, are you using a different entity storage class than the one provided by Drupal core?
Comment #11
salihcenap commented@amateescu No I don't! The error I get is:
Comment #12
amateescu commented@salihcenap, ok, that means it's a different problem than the one reported here. Can you open a new issue for it?
Comment #13
salihcenap commentedOk
Comment #14
plachComment #15
pameeela commented@claudiu.cristea: Thanks for taking part in this issue. If you'd like to help us make sure the 8.8.0 update is as smooth as possible, please consider signing up for the beta testing program at https://goo.gl/forms/bMBTMRSY3sKEscUJ3
Comment #16
MarianT commentedThis worked for me.
I dropped these two tables:
taxonomy_term_field_revision
taxonomy_term_revision
and then drop all tables that begins with 'tmp_' like so:
DROP TABLE IF EXISTS tmp_82a5ectaxonomy_term__parent ,tmp_82a5ectaxonomy_term_field_revision,
etc
and then:
drush updp -y