Export fails when referenced entity no longer exists

Created on 4 September 2024, 9 months ago
Updated 19 September 2024, 9 months ago

Problem/Motivation

When exporting with reference using the "Export processed text dependencies" option, if I have a node that references a now deleted entity, batch fails with the following error:

ResponseText: The website encountered an unexpected error. Try again later.Error: Call to a member function getEntityTypeId() on bool in Drupal\default_content_deploy\Exporter->getEntityReferencesRecursive() (line 1152 of modules/contrib/default_content_deploy/src/Exporter.php). Drupal\default_content_deploy\Exporter->getEntityReferencesRecursive(Object, Array, 7, Array)

I was exporting thousands of nodes, and it was difficult to track down the offending node. I propose we adjust the getEntityReferencesRecursive() method to skip referenced entities that no longer exist ($referenced_entity is a boolean instead of a ContentEntityInterface object), and log the offending node to make it easier to track down.

Steps to reproduce

Create a node that links to a second node in the body field using linkit. Now delete that second node and export content with references. This would also happen if a node references a media item or other entity types where the entity is deleted.

Proposed resolution

We should just skip referenced entities that are returned as a boolean instead of a Node object, and throw a warning to help people fix the content issue.

Remaining tasks

Review patch.

🐛 Bug report
Status

Fixed

Version

2.1

Component

Code

Created by

🇨🇦Canada smulvih2 Canada 🍁

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Production build 0.71.5 2024