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

Created on 20 December 2022, about 2 years ago
Updated 13 September 2024, 4 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 Milan

    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
  • 🇺🇸United States dbdrupal

    I'm having the same issues as others have described. This is a major issue that has been open for over a year? I understand and appreciate those that volunteer their time to build and maintain contrib modules, but could you at least put a disclaimer on the main page warning people not to install this anymore? Are there any manual steps that can be taken to cleanup the mess?

  • 🇦🇺Australia dpi Perth, Australia

    I'm having the same issues as others have described. This is a major issue that has been open for over a year? I understand and appreciate those that volunteer their time to build and maintain contrib modules, but could you at least put a disclaimer on the main page warning people not to install this anymore? Are there any manual steps that can be taken to cleanup the mess?

    This is a collaborative effort. You may choose to participate in contributing code, or you may evaluate the proposed changes at your own risk.

    Clearly, there is unaddressed feedback, that is why it remains unmerged.

    Issues like these may of course be worked around manually, without code changes. Again, at you own risk.

    Otherwise, you can put up with "the mess" that is having one additional unused module installed.

  • 🇺🇸United States dbdrupal

    I will test out the fix dpi and see if that works. For those that write and deploy PHP code, a mess might be less cumbersome than for those that are site builders such as myself. I will report back if removing that function seems to solve the problem for me.

  • 🇺🇸United States dbdrupal

    FYI, this patch does not solve the problem. I continue to receive the error when attempting to delete any column from any table. It also screws up some of my ECA models when I do this. This is a bad error and weaves a tangled web of issues.

  • 🇫🇷France liliplanet Cannes

    Agreed, same here. Field removed from content type, now get 'Drupal\Core\Database\DatabaseExceptionWrapper: SQLSTATE[42S02]: Base table or view not found' on every cron run.

    Unable to uninstall module, says fields pending deletion.

  • 🇺🇸United States dbdrupal

    Can the writers/maintainers of this module provide any guidance on how to cleanup this issue in the database or via some other method? Thanks.

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