Problem/Motivation

I just tried updating a Drupal v8.3.7 site to v8.4.4 and when running drush updb I get this error


SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL     [error]
server version for the right syntax to use near 'SET content_translation_source='und'
WHERE content_translation_source IS NULL' at line 1: UPDATE {} SET content_translation_source=:db_update_placeholder_0
WHERE content_translation_source IS NULL; Array
(
    [:db_update_placeholder_0] => und
)

Performing content_translation_update_8400                  [ok]

It says the "content_translation_update_8400" is ok but that is not true. Every update hook after this one does not get invoked. This causes a very big problem when updating Drupal and the Drupals sites I am maintaining need to be update-to-date.

So, what is the problem here?

Steps to reproduce

Proposed resolution

So far, there are two ways to resolve this
1. Make sure that the entity type definition has a 'data_table' defined in its annotation. See #6.

2. Add a hook to your module, the details are in #8.

Remaining tasks

User interface changes

API changes

Data model changes

Release notes snippet

CommentFileSizeAuthor
#3 2937676.patch912 bytesjcisio
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

martinpe created an issue. See original summary.

cilefen’s picture

Priority: Critical » Major
Issue tags: -content translation

No data is lost according to the issue summary so this is not critical without further analysis.

jcisio’s picture

Status: Active » Needs review
FileSize
912 bytes

The problem is, \Drupal::entityDefinitionUpdateManager()->getDataTable() somehow returns NULL instead of the table name for the entity.

The following patch does not intend to be a fix, but it does not make the problem worse.

martinpe’s picture

+1

I did a similar direct hack.

bhanuprakashnani’s picture

Status: Needs review » Reviewed & tested by the community

The patch applies cleanly.

amateescu’s picture

Status: Reviewed & tested by the community » Postponed (maintainer needs more info)

I think this is actually a problem which needs to be handled elsewhere, most likely for each individual site.

content_translation_update_8400() only loops over entity types which are managed by the content translation manager, which implies that your entity type is translatable. That, in turn, means that the entity type definition needs to provide a data_table in its annotation, at least until #2232465: Deprecate table names from entity definitions is fixed.

jcisio’s picture

FYI, if we use the normal way, we get correctly the data table. It's just \Drupal::entityDefinitionUpdateManager()->getDataTable() that doesn't work here. I didn't try further, as the attached patch worked for this one-shot problem.

facine’s picture

Hi, there is any custom entity without 'data_table', I solved this with a custom update:


/**
 * Implements hook_update_dependencies().
 */
function MY_MODULE_update_dependencies() {
  $dependencies = [];

  $dependencies['content_translation'][8400] = [
    'MY_MODULE' => 8001,
  ];

  return $dependencies;
}

/**
 * Update entity definition.
 */
function MY_MODULE_update_8001(&$sandbox) {
  $entity_schema_repository = \Drupal::getContainer()->get('entity.last_installed_schema.repository');
  $entity_type = $entity_schema_repository->getLastInstalledDefinition('MY_ENTITY_ID');
  $entity_type->set('data_table', 'MY_ENTITY_ID_field_data');
  $entity_schema_repository->setLastInstalledDefinition($entity_type);
}

@see https://www.drupal.org/project/drupal/issues/2328565

Version: 8.4.4 » 8.4.x-dev

Core issues are now filed against the dev versions where changes will be made. Document the specific release you are using in your issue comment. More information about choosing a version.

Version: 8.4.x-dev » 8.9.x-dev

Drupal 8.8.7 was released on June 3, 2020 and is the final full bugfix release for the Drupal 8.8.x series. Branches prior to 8.8.x are not supported, and Drupal 8.8.x will not receive any further development aside from security fixes. Sites should prepare to update to Drupal 8.9.0 or Drupal 9.0.0 for ongoing support.

Bug reports should be targeted against the 8.9.x-dev branch from now on, and new development or disruptive changes should be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.9.x-dev » 9.2.x-dev

Drupal 8 is end-of-life as of November 17, 2021. There will not be further changes made to Drupal 8. Bugfixes are now made to the 9.3.x and higher branches only. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.2.x-dev » 9.3.x-dev
quietone’s picture

Issue tags: +Bug Smash Initiative

Is anyone still experiencing this problem?

The comment in #5 explains that a cause of this would be that an entity type definition is not providing a data_table in its annotation. And thus a solution would be to add the annotation. Also, another workaround using hooks is provided in #8.

Right now I think this could be changed to a support request and 'fixed'.

I'll check first.

quietone’s picture

Category: Bug report » Support request
Priority: Major » Normal
Issue summary: View changes

Updating the IS. And for now changing to a support request.

If you are experiencing this problem, add a comment.

quietone’s picture

Issue tags: +8.4.0 update

Adding update tag.

cilefen’s picture

Status: Postponed (maintainer needs more info) » Closed (outdated)