Problem/Motivation

field_purge_batch() tries to purge fields that have no instances. field_read_instances() does not return instances attached to unknown entity types unless include_inactive is set in the $include_additional parameter. If you delete field instances in the disable hook of a module that provides an entity type, those instances will not be automatically purged. However, the fields will be purged automatically. Every time you uninstall the module, it will leave instances that have no corresponding fields in the field_config_instances table. These orphaned instances can only be deleted manually.

Proposed resolution

Pass include_inactive in the $include_additional parameter before attempting to purge fields.

Remaining tasks

  1. Review patch.
  2. Commit patch.

Comments

darren oh’s picture

Issue summary: View changes
StatusFileSize
new1.11 KB
darren oh’s picture

Assigned: darren oh » Unassigned
darren oh’s picture

Status: Active » Needs review

Status: Needs review » Needs work

The last submitted patch, 1: drupal-field_purge_batch-2337139.patch, failed testing.

darren oh’s picture

StatusFileSize
new1.11 KB

Fixed typo.

darren oh’s picture

Status: Needs work » Needs review
darren oh’s picture

StatusFileSize
new1.16 KB

Changed wrong line.

Status: Needs review » Needs work

The last submitted patch, 7: drupal-field_purge_batch-2337139-7.patch, failed testing.

darren oh’s picture

Status: Needs work » Needs review
StatusFileSize
new1.17 KB
darren oh’s picture

Title: field_purge_batch() falsely assumes that instances attached to unknown entities do not exist » Fields with instances attached to unknown entities are deleted on cron run
taran2l’s picture

darren oh’s picture

Status: Closed (duplicate) » Needs review

This is not a duplicate. The other patch would still allow fields with inactive instances to be deleted before the instances have been deleted.

mcdruid’s picture

Aren't the patches effectively exactly the same?

darren oh’s picture

No, this patch fixes field deletion and the other patch fixes instance deletion.

Status: Needs review » Closed (outdated)

Automatically closed because Drupal 7 security and bugfix support has ended as of 5 January 2025. If the issue verifiably applies to later versions, please reopen with details and update the version.