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

CommentFileSizeAuthor
#3 3048595-3.patch1.22 KBclaudiu.cristea

Comments

claudiu.cristea created an issue. See original summary.

claudiu.cristea’s picture

Issue summary: View changes
claudiu.cristea’s picture

Status: Active » Needs review
StatusFileSize
new1.22 KB

I cannot see other way.

But I'm still curious why \Drupal::entityDefinitionUpdateManager()->getEntityType() doesn't alter the definition via hook_entity_type_alter().

berdir’s picture

\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.

plach’s picture

Status: Needs review » Closed (works as designed)

Definitely, 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.

claudiu.cristea’s picture

Thank 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?

plach’s picture

Shouldn't we emit some warning when using affected functionalities and there is mismatch in definitions?

Do you mean store some flag in state and raise a warning when instantiating the storage or something like along those lines?

claudiu.cristea’s picture

@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?

The entity type %entity_type definition changes are not installed.

salihcenap’s picture

patch did'nt work for me. Still cannot update..

[error]  The entity update process failed while processing the entity type taxonomy_term, ID: 1.
[error]  Update failed: taxonomy_post_update_make_taxonomy_term_revisionable
[error]  Update aborted by: taxonomy_post_update_make_taxonomy_term_revisionable
amateescu’s picture

@salihcenap, are you using a different entity storage class than the one provided by Drupal core?

salihcenap’s picture

@amateescu No I don't! The error I get is:

>  [notice] Update started: taxonomy_post_update_make_taxonomy_term_revisionable
>  [error]  Drupal\Core\Database\IntegrityConstraintViolationException: SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'name' cannot be null: INSERT INTO {tmp_d305d9taxonomy_term_field_data} (tid, revision_id, vid, langcode, name, description__value, description__format, weight, changed, default_langcode, status, revision_translation_affected) VALUES (:db_insert_placeholder_0, :db_insert_placeholder_1, :db_insert_placeholder_2, :db_insert_placeholder_3, :db_insert_placeholder_4, :db_insert_placeholder_5, :db_insert_placeholder_6, :db_insert_placeholder_7, :db_insert_placeholder_8, :db_insert_placeholder_9, :db_insert_placeholder_10, :db_insert_placeholder_11); Array
> (
>     [:db_insert_placeholder_0] => 1
>     [:db_insert_placeholder_1] => 1
>     [:db_insert_placeholder_2] => tags
>     [:db_insert_placeholder_3] => tr
>     [:db_insert_placeholder_4] =>
>     [:db_insert_placeholder_5] =>
>     [:db_insert_placeholder_6] =>
>     [:db_insert_placeholder_7] =>
>     [:db_insert_placeholder_8] =>
>     [:db_insert_placeholder_9] =>
>     [:db_insert_placeholder_10] =>
>     [:db_insert_placeholder_11] => 1
> )
>  in Drupal\Core\Database\Connection->handleQueryException() (line 689 of /var/www/drupal8/web/core/lib/Drupal/Core/Database/Connection.php).
>  [error]  The entity update process failed while processing the entity type taxonomy_term, ID: 1.
>  [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.
amateescu’s picture

@salihcenap, ok, that means it's a different problem than the one reported here. Can you open a new issue for it?

salihcenap’s picture

Ok

plach’s picture

Issue tags: -8.7.0 upgrade path +8.7.0 update
pameeela’s picture

@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

MarianT’s picture

This 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