diff --git a/core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorage.php b/core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorage.php index 2188f63..7ac9c7b 100644 --- a/core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorage.php +++ b/core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorage.php @@ -1591,7 +1591,12 @@ public function finalizePurge(FieldStorageDefinitionInterface $storage_definitio * {@inheritdoc} */ public function countFieldData($storage_definition, $as_bool = FALSE) { - $table_mapping = $this->getTableMapping(); + // The storage definition might be different stored to the one in the DB, so + // fetch the table mapping from an up to date one, using the passed in + // storage definition. + $storage_definitions = $this->entityManager->getFieldStorageDefinitions($this->entityTypeId); + $storage_definitions[$storage_definition->getName()] = $storage_definition; + $table_mapping = $this->getTableMapping($storage_definitions); if ($table_mapping->requiresDedicatedTableStorage($storage_definition)) { $is_deleted = $this->storageDefinitionIsDeleted($storage_definition); diff --git a/core/modules/system/src/Tests/Entity/Update/UpdateApiEntityDefinitionUpdateTest.php b/core/modules/system/src/Tests/Entity/Update/UpdateApiEntityDefinitionUpdateTest.php index fcfff4a..78f19c0 100644 --- a/core/modules/system/src/Tests/Entity/Update/UpdateApiEntityDefinitionUpdateTest.php +++ b/core/modules/system/src/Tests/Entity/Update/UpdateApiEntityDefinitionUpdateTest.php @@ -72,6 +72,9 @@ public function testSingleUpdates() { $this->enableUpdates('entity_test', 'entity_definition_updates', 8001); $this->applyUpdates(); + // Ensure the 'entity_test__user_id' table got created. + $this->assertTrue(\Drupal::database()->schema()->tableExists('entity_test__user_id')); + // Check that data was correctly migrated. $entity = $this->reloadEntity($entity); $this->assertEqual(count($entity->user_id), 1);