Entity Definition Update Manager should raise exception on no-op/unsupported changes

Created on 20 April 2020, over 4 years ago
Updated 10 August 2023, over 1 year ago

In #2542748: Automatic entity updates can fail when there is existing content, leaving the site's schema in an unpredictable state β†’ , core stopped supporting automated/auto-magical updating of entity field definitions post entity install. The CR for this change states:

...that magic was removed and now changes to the entity schema are to be included as regular update functions.

Good stuff. As a result, the Entity Definition Update Manager provides a number of helper functions for updating these definitions "correctly."

Custom module maintainers may, however, attempt updates that will result in either a no-op or a mismatched field definition vs. an installed schema. Consider the example of a string field; a developer may believe it possible to update the schema thusly:

$entity_definition_update_manager = \Drupal::entityDefinitionUpdateManager();
/** @var \Drupal\Core\Field\BaseFieldDefinition $field_storage_definition */
$field_storage_definition = $entity_definition_update_manager->getFieldStorageDefinition('field_name', 'entity_name');
$field_storage_definition->setSetting('max_length', 51);
$entity_definition_update_manager->updateFieldStorageDefinition($field_storage_definition);

This will update the definition, partly, however the schema of the backing field will not be changed and the entity will continue to show as needing an update in the Status Report UI. Since the UI message does not provide context beyond "needs update," this can result in frustration and confusion.

Since the entity definition update manager is a developer-facing API with no UI attached, it would be appropriate to throw some type of runtime exception when we can detect such changes won't "take."

πŸ“Œ Task
Status

Active

Version

11.0 πŸ”₯

Component
FieldΒ  β†’

Last updated 1 day ago

Created by

πŸ‡ΊπŸ‡ΈUnited States bradjones1 Digital Nomad Life

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • πŸ‡©πŸ‡ͺGermany Anybody Porta Westfalica

    Totally agree such issues have to be raised at the development level, so that the risk of having them in the status report after deployment is mitigated. Site owners reading the status report will be confused, and this is surely a developer job to understand and solve as early as possible!

Production build 0.71.5 2024