Remove orphaned (dangling) entity references when an entity is deleted

Created on 9 June 2018, over 6 years ago
Updated 4 August 2023, over 1 year ago

Problem/Motivation

Entity reference field items are not removed when the referenced entity is deleted.

E.g.

  1. Create taxonomy term with tid 123 "trees".
  2. Create node "pine" with nid 456 tagged with "trees".
  3. Delete the "trees" term. Nid 456 will still be related to tid 123 even though there is no longer such a term.

Mostly this isn't a problem. Some examples where it can cause problems:

  • Search facets with an incorrect count of results.
  • Cryptic error messages when editing entities that contain collapsed Paragraphs.
  • Null fields in GraphQL results (which is invalid GraphQL).
  • Acquia's Cohesion product (see "Why is my Cohesion layout table so large" which points to this issue)

What can I do until a patch has been created?

Why doesn't a fix for this already exist in core?

  • There are scenarios where dangling references shouldn't be automatically cleaned up (if you need a human, or some other system to take action).
  • It's a performance challenge. There may be tens of thousands (or more) dangling references to clean up.

Proposed resolution

In interactive scenarios - like the entity delete confirm form - ask the editor if they want to delete the orphaned references:

  • immediately (default)
  • in the background or
  • don't remove the references at all (not recommended)

In a non-interactive environment (PHP API, REST API) always use the second option.

Remaining tasks

  • Write code
  • ...
  • Profit

User interface changes

New radio group on the entity delete confirmation form (and bulk operations confirm form too?).

API changes

TBD

Data model changes

None

πŸ› Bug report
Status

Active

Version

11.0 πŸ”₯

Component
EntityΒ  β†’

Last updated 14 minutes ago

Created by

πŸ‡΅πŸ‡±Poland blazey

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