Parent Deletion Issue for Entity Type without Bundles

Created on 3 March 2025, about 1 month ago
Updated 4 March 2025, about 1 month ago

Problem/Motivation

I encountered an issue with the parent deletion process when running it on a custom entity type without bundles that has its relationship defined on a UI-defined field: details below.

The parent deletion query identifies any parent entities which should be deleted after the child entity has been deleted, though this functionality seems to centered around bundles. If the relationship is defined on a base field, the query runs for all bundles of the parent entity type. If the relationship is defined on a non-base field type, such as a config field, the query adds a condition to specify the bundle (via bundle key).

However, bundles are optional — if the entity type does not use bundles and the entity relationship is defined on field created via the UI, this condition yields a null value for the bundle key and causes an error in the query. Thus, this prevents the parent deletion process from completing.

Steps to reproduce

  1. Create two custom entity types without bundles: Tournament and Match (these are arbitrary, can be any name).
  2. Via the UI, add an Entity Reference field on the Match entity type relating to the Tournament entity type.
    1. Set the Behavior for Match entities when a Tournament entity referenced by this field is deleted to "always delete".
  3. Create a Tournament entity.
  4. Create several Match entities, and populate the Tournament field on each with a reference to the Tournament entity .
  5. Delete the Tournament entity.
  6. Run drush queue:list in the terminal to see the list of items for deletion.
  7. Run drush queue:run entity_reference_delete_parent_query to encounter the error in the console.
  8. Records remain undeleted.

Proposed resolution

One solution would be to check the list of bundles an entity type reports using. If only one is found, omit the condition to specify the bundle type.

🐛 Bug report
Status

Active

Version

1.0

Component

Code

Created by

🇨🇦Canada strakez

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.

  • 🇮🇹Italy apaderno Brescia, 🇮🇹
  • 🇬🇧United Kingdom joachim

    It's been a long time since I wrote this module, so I don't remember how it all works.

    But even entity types that have no bundles actually have a bundle -- it has the same name as the entity type ID. I think the change should be doing something with that.

Production build 0.71.5 2024