4

I'm getting an "unexpected error" when I try to view a list of taxonomy terms. I recently updated to 8.7, though I have a feeling the problem has been around since before the update. Here's the error as it appears in watchdog:

Drupal\Core\Database\DatabaseExceptionWrapper: SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ') AS expression FROM tfr INNER JOIN tr ON tfr. = tr. AND tr. = 0 INNER JOIN (S' at line 1: SELECT tfr.tid AS tid, MAX(tfr.) AS expression FROM {} tfr INNER JOIN {} tr ON tfr. = tr. AND tr. = 0 INNER JOIN (SELECT t.tid AS tid, t.langcode AS langcode, MAX(t.) AS expression FROM {} t WHERE t. = :db_condition_placeholder_0 GROUP BY t.tid, t.langcode) mr ON tfr. = mr. AND tfr.langcode = mr.langcode GROUP BY tfr.tid; Array ( [:db_condition_placeholder_0] => 1 ) in Drupal\taxonomy\TermStorage->getTermIdsWithPendingRevisions() (line 404 of /Applications/MAMP/htdocs/libnews/core/modules/taxonomy/src/TermStorage.php).

And I don't know if this related, but I am also getting an error when I try to update my database via drush:

Error: Call to a member function getKey() on null in system_update_8702() (line 2278 of /Applications/MAMP/htdocs/libnews/core/modules/system/system.install) #0

This is outside my area of expertise, so I'm pretty stumped.

1

I got a similar error on my server too. I had to change the function in TermStorage.php to get it to work.

Just a warning, this core hack and should be reverted once it is fixed in core. Replace getTermIdsWithPendingRevisions() with the following:

  public function getTermIdsWithPendingRevisions() {
$table_mapping = $this->getTableMapping();
$id_field = $table_mapping->getColumnNames($this->entityType->getKey('id'))['value'];
$revision_field = $table_mapping->getColumnNames($this->entityType->getKey('revision'))['value'];
$rta_field = $table_mapping->getColumnNames($this->entityType->getKey('revision_translation_affected'))['value'];
$langcode_field = $table_mapping->getColumnNames($this->entityType->getKey('langcode'))['value'];
$revision_default_field = $table_mapping->getColumnNames($this->entityType->getRevisionMetadataKey('revision_default'))['value'];

$query = $this->database->select($this->getRevisionDataTable(), 'tfr');
$query->fields('tfr', [$id_field]);
$query->addExpression("MAX(tfr.$revision_field)", $revision_field);

$query->join($this->getRevisionTable(), 'tr', "tfr.$revision_field = tr.$revision_field AND tr.$revision_default_field = 0");

$inner_select = $this->database->select($this->getRevisionDataTable(), 't');
$inner_select->condition("t.$rta_field", '1');
$inner_select->fields('t', [$id_field, $langcode_field]);
$inner_select->addExpression("MAX(t.$revision_field)", $revision_field);
$inner_select
  ->groupBy("t.$id_field")
  ->groupBy("t.$langcode_field");

$query->join($inner_select, 'mr', "tfr.$revision_field = mr.$revision_field AND tfr.$langcode_field = mr.$langcode_field");

$query->groupBy("tfr.$id_field");
return 0;
//return $query->execute()->fetchAllKeyed(1, 0);

}

  • Thanks! That worked like a charm. In your case, do you know what caused the initial problem? – JOakland May 7 at 18:33
  • This happens when the entity type definition (stored in key_value table) is malformed. – ummdorian Jun 21 at 20:33
  • If you're going to patch this function I would suggest returning an empty array at the beginning, rather than returning 0 at the end. This would probably cause problems with content moderation, so check that functionality if applicable. – ummdorian Jun 21 at 21:11
1

This is related to the entity definitions which are not updated for Taxonomy terms. Your workaround resolves the error but the entities are still not updated. Take a look to the status report (/admin/reports/status) you will find this error:

Mismatched entity and/or field definitions The following changes were detected in the entity type and field definitions. Taxonomy term The Taxonomy term entity type needs to be updated. The Revision ID field needs to be installed. The Revision create time field needs to be installed. The Revision user field needs to be installed. The Revision log message field needs to be installed. The Default revision field needs to be installed. The Revision translation affected field needs to be installed.

No solution found for now because Drupal 8.7.x doesn't support drush entity update anymore.

Any help ?

  • As of 8.7 entity updates are run with other database updates rather than separately. If drush updb, or /update.php runs successfully than there isn't an easy way to get your entity type definition to match the actual schema. – ummdorian Jun 21 at 20:36
0

Try make update with sites.com/update.php. It solved this problem for me.

  • This is the same as running "drush updatedb" (which is what I was doing originally) and throws the same error. – JOakland May 23 at 17:15
  • But sometimes drush updb works with an error, but the update via the web interface goes well (and vice versa). At least I'm trying both. – Alexey Dyomin May 24 at 16:17
  • And fixing core - the bad idea. I would use patches for it. – Alexey Dyomin May 24 at 16:22
0

I have Drupal core version 8.7.2 and drush updb -y fixed the error:

taxonomy module : Update taxonomy terms to be revisionable. Remove the 'hierarchy' property from vocabularies.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.