Changing the target type of an entity reference does not trigger an field definition update, leading to broken sites

Created on 11 December 2017, about 7 years ago
Updated 14 December 2023, about 1 year ago

Problem/Motivation

If you change the target type of an entity reference field, Drupal does not detect this as a field definition update, because the schema is identical before and after the change. Thus, it's easy to forget to call EntityDefinitionUpdateManager::updateFieldStorageDefinitions() as part of the update hook, because e.g. drush entity-updates does not report it. In particular if you are not providing an update path for custom modules but instead relying solely on drush entity-updates (which is valid if you know the exact code and database state of all your environments) this can lead to problems.

Since the field storage definition will not be updated the old entity type ID will still be referenced, even if the old entity type is uninstalled after the change. This will then lead to fatal errors where the last installed field storage definitions are used.

Proposed resolution

It seems like we should provide field item classes the possibility to participate in the decision whether or not they need storage schema changes, i.e. delegate from SqlContentEntityStorageSchema::requiresFieldStorageSchemaChanges() somehow.

πŸ› Bug report
Status

Closed: duplicate

Version

9.5

Component
EntityΒ  β†’

Last updated 1 day ago

Created by

πŸ‡©πŸ‡ͺGermany tstoeckler Essen, Germany

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.

Production build 0.71.5 2024