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);

}

| improve this answer | |
  • Thanks! That worked like a charm. In your case, do you know what caused the initial problem? – JOakland May 7 '19 at 18:33
  • This happens when the entity type definition (stored in key_value table) is malformed. – ummdorian Jun 21 '19 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 '19 at 21:11
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.

| improve this answer | |

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.