DateRecurOccurrences::onEntityTypeDelete makes it impossible to delete an entity type and its code at the same time

Created on 20 December 2022, over 1 year ago
Updated 17 August 2023, 11 months ago

Problem/Motivation

As per #3067024: Add test coverage for uninstalling revisionable entity types whose code doesn't exist anymore it should be possible to uninstall an entity type and delete its definition in code at the same time, however DateRecurOccurrences::onEntityTypeDelete makes that impossible due to it building field definitions which ends up in EntityFieldManager::buildBaseFieldDefinitions which calls $entity_type = $this->entityTypeManager->getDefinition($entity_type_id); that then fails as the plugin no longer exists.

Steps to reproduce

Try to uninstall an entity type with an update hook like so, while also having date_recur enabled and the entity type definition (i.e the class) removed from the codebase.

  $entity_update_manager = \Drupal::entityDefinitionUpdateManager();
  $entity_type = $entity_update_manager->getEntityType('entity_type_id');
  if ($entity_type) {
    $entity_update_manager->uninstallEntityType($entity_type);
  }

Proposed resolution

Remove this hook entirely. We already have onFieldStorageDefinitionDelete which doesn't have to gather fields up like before and when removing an entity type, the field storage definitions should be removed anyway.

🐛 Bug report
Status

Needs work

Version

3.4

Component

Code

Created by

🇦🇺Australia acbramley

Live updates comments and jobs are added and updated live.
  • Needs tests

    The change is currently missing an automated test that fails when run with the original code, and succeeds when the bug has been fixed.

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.

  • 🇮🇹Italy kopeboy Mainland

    Similar errors for me, even happening when I delete an unrelated entity (never used/ing a date field)!

    Drupal\Core\Database\DatabaseExceptionWrapper: SQLSTATE[42S02]: Base table or view not found: 1146 Table 'db.date_recur__commerce_order_item__field_every' doesn't exist: DELETE FROM "date_recur__commerce_order_item__field_every" WHERE "entity_id" = :db_condition_placeholder_0; Array ( [:db_condition_placeholder_0] => 26 ) in Drupal\date_recur\DateRecurOccurrences->onEntityDelete() (line 153 of /var/www/html/web/modules/contrib/date_recur/src/DateRecurOccurrences.php).

  • 🇫🇷France zenimagine

    yes and it's been going on for over a year, this module is installed on my Drupal and I have no use for it. It would be nice to show a "Unable to uninstall" warning on the module page.

  • 🇦🇺Australia dpi Perth, Australia
Production build 0.69.0 2024