Problem/Motivation

When disabling modules that create fields this error is sometimes displayed. The message does not make it clear what caused the issue or how to fix it which is frustrating for users.

If you want to fix the underlying issue that causes this message check out #943772: field_delete_field() and others fail for inactive fields

The reason the fields are not deleted immediately on uninstall is that the database could be very, very large, and deleting all fields at the same time might time out the request, leaving the database in an unknown state. That's why cron is used to delete the fields.

Proposed resolution

Change message to be more descriptive and more helpful in resolving the issue

There are Fields pending deletion that were created by a module you just tried to disable. Delete offending fields now or try running cron, it might fix this issue.

The error message is produced by field_system_info_alter() in core/modules/field/field.module.

Also, give the user a report of how many such field entries exist, and if there are more than some arbitrary threshold, don't allow the user to try to delete them all at once.

Remaining tasks

  1. Finalize the message text
  2. Write a patch

Original report by [joachim]

I saw this message in my modules list and it completely baffled me.
I only found out I had to run cron thanks to a comment buried in an issue on a contrib module somewhere.
When this text appears in the module admin page it should be linked to further help.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

jhodgdon’s picture

Title: provide a help topic for "Required by Drupal (Fields Pending Deletion)" » Message "Required by Drupal (Fields Pending Deletion)" baffles users
Version: 7.x-dev » 8.x-dev
Component: documentation » base system
Issue tags: +Needs backport to D7

Thanks for reporting this!

Moving to 8.x (we fix bugs there and then backport if possible/necessary), and base system (this is in-code text).

NathanM’s picture

Ditto for me. I have several modules I would like to disable, (Organic Groups and Reply), and after doing everything I can to delete the fields, I am confronted with this "Fields pending deletion" message, which prevents me from disabling the modules. Everywhere else I have read has recommended running cron, (sometimes multiple times), which will finally delete the fields and allow me to disable the module. I have run cron probably 50 times, and am still getting this message. Eventually I had to go in and delete all references to the fields through the database, taking my site down for several hours in the process because the references were located in so many different tables. This is extremely frustrating.

webchick’s picture

sven.lauer’s picture

+1 on having an extensive help text linked with this message.

What @NathanM describes in #2 does sound more like there is problem with the purging of field data which is independent from how this message should be phrased/explained in help texts.

jbrown’s picture

I found this message very helpful, but it should really mention cron.

Mile23’s picture

There should be a 'delete offending fields now' button, in addition to an 'run cron to delete them, if you want' button.

Also: #1199946: Disabled modules are broken beyond repair so the "disable" functionality needs to be removed

chrowe’s picture

Issue summary: View changes

improve issue summary

chrowe’s picture

Issue summary: View changes

better Issue summary

gbirch’s picture

Issue summary: View changes

Altered summary to add reference to code.

yched’s picture

Crosslinking to #1264728: Refresh field 'active' state in module_enable() / _disable() which would mitigate that in "good" cases (fields with few values, e.g just evaluating a field type module and removing it)

yched’s picture

The real fix would be a "purge everything now through batch API" button somewhere in the UI - probably on admin/reports/fields.
Not possible for me to work on this right now, but any takers welcome.

drewish’s picture

My problem is that it doesn't even tell you which fields to delete. I've removed the only instance of the field I remember creating. I ran cron a bunch. I guess I'll go dig into the field system to get a list of the fields and see what entity has another field of this type.

yched’s picture

@drewish : the admin/reports/fields screen displays the module name in the "Field Type" column. You need to delete all the fields where the module is the one you want to disable.

fizk’s picture

Status: Active » Needs review
FileSize
563 bytes

This patch changes "Fields pending deletion" to "Fields pending deletion - run cron to delete the fields", with a link to the run cron page.

triple5’s picture

This doesn't work, however, when cron runs are not enough.
like in the media module, I had created one single field to try this module didn't work, now it is not possible to cleanly uninstall the module.
I have run cron 10 times now

The way should be to display the fields that are pending deletion and offer a way to erase them from the database without cron, but with a specific link. The first link to delete the fields was not very helpful it lets you guess which of the fields you need to delete... There should be the hook for the final deletion of those fields.

steinmb’s picture

@triple5 there is a discussion going on at #1199946: Disabled modules are broken beyond repair so the "disable" functionality needs to be removed that is related to this issue.

jenlampton’s picture

It's doubly frustrating that even once you do figure out that you can't disable/uninstall a module because you need to run cron to clean up your data, that even after you run cron, you still can't disable/uninstall the module. It *appears* as though running cron changed nothing, so makes you think that's not the solution, even when it is. You just need to do it N more times.

Hold on, can't cron batch? Why is it even necessary to run cron more than once? Can we fix that too?

chrisolof’s picture

Agreed - this message also leads to unfixable bug reports on various modules that make use of the Field API. Simply Google the message text to see some examples.

@jenlampton
In some situations there may be quite a bit of data to purge, so having it all purged in a single cron run might not be scalable (cron could sit there running for a long, long time).

I'm going to take a stab at something along the lines of #8, where we let deleted Field API data purge by way of small batches at cron run, but also offer a "Purge all deleted Field API data" option to those who want it gone now (utilizing the batch api).

If all goes well I'll follow up with a patch soon.

batigolix’s picture

batigolix’s picture

Issue summary: View changes

improve issue summary

alansaviolobo’s picture

Issue summary: View changes
FileSize
628 bytes
666 bytes

rerolled.
should we also be adding the solution as described in #16 as well ?

Status: Needs review » Needs work

The last submitted patch, 17: message_required_by-1331922-1.patch, failed testing.

Sutharsan’s picture

Rerolled the patch in #17.

I leave the issue at needs work, because the tests needs to be fixed. At least FieldUninstallValidatorTest.php fails due to the use of Drupal::url.

Version: 8.0.x-dev » 8.1.x-dev

Drupal 8.0.6 was released on April 6 and is the final bugfix release for the Drupal 8.0.x series. Drupal 8.0.x will not receive any further development aside from security fixes. Drupal 8.1.0-rc1 is now available and sites should prepare to update to 8.1.0.

Bug reports should be targeted against the 8.1.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.2.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.1.x-dev » 8.2.x-dev

Drupal 8.1.9 was released on September 7 and is the final bugfix release for the Drupal 8.1.x series. Drupal 8.1.x will not receive any further development aside from security fixes. Drupal 8.2.0-rc1 is now available and sites should prepare to upgrade to 8.2.0.

Bug reports should be targeted against the 8.2.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.3.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

alexanderpas’s picture

This issue can be replicated on Drupal 8.2.4 with the following steps:

1. Install Drupal using the minimal profile.
2. Uninstall the node module.

As a result, the Text module can't be uninstalled because the body field from node is still pending deletion after the node module has been uninstalled.

There is no content on sites that were just created with the minimal profile.

TheodorosPloumis’s picture

Just a notice here although it may not be so relevant.

For 8.2.x I got a similar message (Required by ... (Fields Pending Deletion)) while trying to uninstall a module because there were Path aliases on the database. After deleting the path aliases I could uninstall the module.

Version: 8.2.x-dev » 8.3.x-dev

Drupal 8.2.6 was released on February 1, 2017 and is the final full bugfix release for the Drupal 8.2.x series. Drupal 8.2.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.3.0 on April 5, 2017. (Drupal 8.3.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.3.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

colan’s picture

Let's forget about messages telling the user to run cron, when that may not even work. The uninstall action should actually purge the fields as part of its run. By explicitly uninstalling a module, the user is saying, "I don't want anything to do with this module anymore." So it makes no sense to wait for cron. Do it now.

frederickjh’s picture

I just ran into this as well testing a module. Something needs to be done. The message

Fields pending deletion

although true, does not provide any helpful information to the user on how to solve the issue and actually complete the tasks at hand, uninstalling a module.

A message to run cron is not enough. It seems that I am finding information that the cron run only deletes 10 rows of data at a time. Because of this it may be necessary to run cron multiple times before all the fields pending deletion have been deleted. How many times the user does not know.

The fact that cron on sites is run at different time intervals and the number of fields pending deletion, have led to lots of posts of frustration that the system waits arbitrary amounts of time before deleting the fields and that running cron even multiple times does not delete them.

We need clarity in the error message that includes how to resolve the issue and a way that people can check if fields are queue for a pending deletion.

frederickjh’s picture

I might also add that it also baffles the users as to why the 'field_deleted_data_' tables are so long in the database after deleting fields. A better error message could help clear up that confusion too.

See: Fields 'field_deleted_data_' Tables appear in Database after Field Deletions

Mile23’s picture

Added an explanation for why this 'error' is presented. It's not really an error.

Also added some more behavior to the solution: We should report what's up, with an accounting of how many records might be effected by deletion, and arbitrarily decide whether or not the user can go ahead and click a 'delete them now' link.

ex DJ’s picture

I must have run cron 50 times and still I'm stuck with Field Token Value. I think it's causing problems in Views and I really need to remove it. Any additional information would be most helpful.

ex DJ’s picture

I must have run cron 50 times and still I'm stuck with Field Token Value. I think it's causing problems in Views and I really need to remove it. Any additional information would be most helpful.

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.6 was released on August 2, 2017 and is the final full bugfix release for the Drupal 8.3.x series. Drupal 8.3.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.4.0 on October 4, 2017. (Drupal 8.4.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.4.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

colan’s picture

Anonymous’s picture

Recently ran across this issue when I uninstalled media, then I wanted to remove video_embed_field. It kept saying "Fields pending deletion" no matter how many times I ran cron. So basically the advice can be wrong here.

I also needed to know what field was causing this problem, and the patches here don't give that. So this patch will:

- Give the field name causing the error
- Say that running cron may solve the problem

In my case it now tells me:

Field pending deletion: media.field_video. Running cron may delete the field.

Anonymous’s picture

Status: Needs work » Needs review
Anonymous’s picture

@colan I don't think that issue would fix it. That fixes the root cause of zombie fields most likely, but not the "pending" state when cron hasn't been run yet to clean up deleted fields. At least that's how I understand it.

The last submitted patch, 19: message_required_by-1331922-19.patch, failed testing. View results

Status: Needs review » Needs work

The last submitted patch, 34: 1331922_fields_pending_deletion_is_unhelpful.patch, failed testing. View results

Anonymous’s picture

Anonymous’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 39: 1331922_fields_pending_deletion_is_unhelpful_39.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

Anonymous’s picture

Status: Needs work » Needs review
FileSize
3.24 KB

Status: Needs review » Needs work
fgm’s picture

Any reason why modules could not run batches during hook_uninstall() ? Sure, it doesn't include a "sandbox" batch tracker like hook_update_N() (wouldn't it be a good idea to add one ?), but does that preclude actually running a batch ?

Anonymous’s picture

Another try on the failing test

Anonymous’s picture

Status: Needs work » Needs review
moreb.mohammad@gmail.com’s picture

to solve this issue tray to delete module folder manually after delete run crone many times it should solve.

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.4 was released on January 3, 2018 and is the final full bugfix release for the Drupal 8.4.x series. Drupal 8.4.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.5.0 on March 7, 2018. (Drupal 8.5.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.5.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.6 was released on August 1, 2018 and is the final bugfix release for the Drupal 8.5.x series. Drupal 8.5.x will not receive any further development aside from security fixes. Sites should prepare to update to 8.6.0 on September 5, 2018. (Drupal 8.6.0-rc1 is available for testing.)

Bug reports should be targeted against the 8.6.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

stevenlafl’s picture

stevenlafl’s picture

Version: 8.6.x-dev » 8.7.x-dev

Version: 8.7.x-dev » 8.8.x-dev

Drupal 8.7.9 was released on November 6 and is the final full bugfix release for the Drupal 8.7.x series. Drupal 8.7.x will not receive any further development aside from security fixes. Sites should prepare to update to 8.8.0 on December 4, 2019. (Drupal 8.8.0-beta1 is available for testing.)

Bug reports should be targeted against the 8.8.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.9.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.7 was released on June 3, 2020 and is the final full bugfix release for the Drupal 8.8.x series. Drupal 8.8.x will not receive any further development aside from security fixes. Sites should prepare to update to Drupal 8.9.0 or Drupal 9.0.0 for ongoing support.

Bug reports should be targeted against the 8.9.x-dev branch from now on, and new development or disruptive changes should be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

berenddeboer’s picture

How to force Drupal to clear out fields pending deletion:

drush php:eval 'field_purge_batch(50000);' 

You may need to provide an even bigger value. When this command returns quickly, uninstall will work.

catch’s picture

Version: 8.9.x-dev » 9.2.x-dev
Issue tags: +Bug Smash Initiative

This is still valid, the proposed patch seems OK except I'm not sure what hasContainer() is doing there, should it be checking permissions to run cron instead? Or that we're not in a CLI request?

Version: 9.2.x-dev » 9.3.x-dev

Drupal 9.1.10 (June 4, 2021) and Drupal 9.2.10 (November 24, 2021) were the last bugfix releases of those minor version series. Drupal 9 bug reports should be targeted for the 9.3.x-dev branch from now on, and new development or disruptive changes should be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.15 was released on June 1st, 2022 and is the final full bugfix release for the Drupal 9.3.x series. Drupal 9.3.x will not receive any further development aside from security fixes. Drupal 9 bug reports should be targeted for the 9.4.x-dev branch from now on, and new development or disruptive changes should be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

ressa’s picture

Related issues: +#2889354: Cannot uninstall

I just ran into this, where I had to run Cron, in order to uninstall a module. I got this odd error message, even though the field was already deleted:

$ drush un field_token_value
In PmCommands.php line 203:
  field_token_value: Fields pending deletion

The updated message in the patch is a big improvement, immediately showing an actionable solution:

Field pending deletion: field_token_value. Running cron may delete the field.

smustgrave’s picture

Version: 9.4.x-dev » 10.1.x-dev
Status: Needs review » Needs work

The last patch or MR doesn't apply to the target branch, please reroll the code so that it can be reviewed by the automated testbot.

Not sure what additional changes are needed for 10.1

Version: 10.1.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.