Problem/Motivation

When a module defines a custom FieldType plugin (for example, custom_field_type) and this FieldType storage is implemented in a field.storage YAML file (for example in field.storage.commerce_product.custom_field.yml), the module cannot be uninstalled anymore because the error The %field_type_label field type is used in the following field: @fields is triggered by Drupal\field\FieldUninstallValidator.

This is logical behavior because normally the FieldType plugin should not be removed as long as implementations exist. However, in some scenarios removal of the plugin should also trigger removal of dependent implementations. This would be the case for example when the FieldType storage implementation YAML exists in the same module as the FieldType plugin.

Proposed resolution

Do not abort the uninstall procedure in Drupal\field\FieldUninstallValidator if the module that is being removed contains the FieldType plugin when it is defined as an enforced module dependency in the FieldType storage implementation that would otherwise trigger the abortion.

Remaining tasks

Does the patch still apply?
Review
Commit

API changes

Any field storage definition that needs to be deleted should include the module name (example_module) that defines the FieldType plugin an enforced module dependency with the following YAML code:

dependencies:
  module:
    - example_module
  enforced:
      module:
        - example_module

Comments

Plankje created an issue. See original summary.

Plankje’s picture

StatusFileSize
new1.98 KB
Plankje’s picture

Issue summary: View changes
Plankje’s picture

Priority: Normal » Major
Status: Active » Needs review
StatusFileSize
new1.98 KB

Fixed file name of patch

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

Drupal 8.4.0-alpha1 will be released the week of July 31, 2017, which means new developments and disruptive changes should now 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.

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

Drupal 8.5.0-alpha1 will be released the week of January 17, 2018, which means new developments and disruptive changes should now 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.6.x-dev » 8.7.x-dev

Drupal 8.6.0-alpha1 will be released the week of July 16, 2018, which means new developments and disruptive changes should now 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.

joachim’s picture

Status: Needs review » Needs work
Issue tags: -FieldUninstallValidator, -field storage, -FieldType

Good catch!

> Any field storage definition that needs to be deleted should include the module name (example_module) that defines the FieldType plugin an enforced module dependency with the following YAML code:

I don't think that's a good API change. Automatic config dependency calculation is very useful, and we shouldn't be removing part of it.

jsacksick’s picture

jsacksick’s picture

The Commerce Recurring module is affected by this bug (See #2924965: [PP-1] Module does not uninstall cleanly (dependency issue)). It cannot be uninstalled because of this bug...

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

Drupal 8.7.0-alpha1 will be released the week of March 11, 2019, which means new developments and disruptive changes should now be targeted against the 8.8.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

handkerchief’s picture

Any news on this?

thronedigital’s picture

Would be curious as well where we are at with this?

dscl’s picture

Assigned: Plankje » Unassigned

Unassigning the issue given that Plankje is clearly not working on that anymore.
This may lead it to be picked up by other contributor.

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

Drupal 8.8.0-alpha1 will be released the week of October 14th, 2019, which means new developments and disruptive changes should now be targeted against the 8.9.x-dev branch. (Any changes to 8.9.x will also be committed to 9.0.x in preparation for Drupal 9’s release, but some changes like significant feature additions will be deferred to 9.1.x.). For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

thronedigital’s picture

Update please.

dercheffe’s picture

Any news about this issue?

aleevas’s picture

StatusFileSize
new2.41 KB
new1.88 KB

Trying to reroll for last versions.

dercheffe’s picture

Status: Needs work » Needs review

If the patches are rerolled they need to reviewed or am I wrong? So changing issue status.

aleevas’s picture

@dercheffe
you're absolutely right.
Thank you!

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

Drupal 8.9.0-beta1 was released on March 20, 2020. 8.9.x is the final, long-term support (LTS) minor release of Drupal 8, which means new developments and disruptive changes should now 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.

jmoruzi’s picture

Any news/updates about this?

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

Drupal 9.1.0-alpha1 will be released the week of October 19, 2020, which means new developments and disruptive changes should now be targeted for the 9.2.x-dev branch. For more information see the Drupal 9 minor version schedule and the Allowed changes during the Drupal 9 release cycle.

xamount’s picture

I'm willing to pay USD$25 to get this bug squashed and committed to core. Any takers?

joachim’s picture

Status: Needs review » Needs work
  1. +++ b/core/modules/field/src/FieldUninstallValidator.php
    @@ -53,11 +53,21 @@ public function validate($module) {
    +      $hasDeleted = FALSE;
    

    The variable name should be in snake_case.

  2. +++ b/core/modules/field/src/FieldUninstallValidator.php
    @@ -53,11 +53,21 @@ public function validate($module) {
    +        if ($field_storage->isDeleted()) {
    +          $hasDeleted = TRUE;
    +          continue;
             }
    

    This logic needs a comment to explain what's being done.

xamount’s picture

I have tested the patch #18 and it fixed this issue.

I have also made the changes you suggested and attached a new patch. Please review.

xamount’s picture

Status: Needs work » Needs review
anmolgoyal74’s picture

StatusFileSize
new1.98 KB
new1.37 KB

Looks like xamount has uploaded the interdiff as patch.

xamount’s picture

ahh my bad, good catch! sorry about that.

zenimagine’s picture

Hi, has anyone successfully uninstalled "Commerce Recurring Framework" ?

xamount’s picture

@zenimagine Yes I have. Here are the steps:

Step 1: Apply the patch from this issue queue

Step 2: In the commerce_recurring module (8.x) inside of config/install you have to update ALL the field.storage... yml files to the API changes suggested at the top of this page.

For e.g. in commerce_recurring/config/install/field.storage.commerce_order.billing_period.yml

before:

langcode: en
status: true
dependencies:
  module:
    - commerce_order
    - commerce_recurring
id: commerce_order.billing_period
field_name: billing_period
entity_type: commerce_order
type: commerce_billing_period
settings: {  }
module: commerce_recurring
locked: true
cardinality: 1
translatable: false
indexes: {  }
persist_with_no_fields: false
custom_storage: false

after:

langcode: en
status: true
dependencies:
  module:
    - commerce_order
    - commerce_recurring
  enforced:
      module:
        - commerce_order
        - commerce_recurring
id: commerce_order.billing_period
field_name: billing_period
entity_type: commerce_order
type: commerce_billing_period
settings: {  }
module: commerce_recurring
locked: true
cardinality: 1
translatable: false
indexes: {  }
persist_with_no_fields: false
custom_storage: false

Step 3: After you have updated all the field.storage yml files inside of config/install then you need to reimport the config with a command such as drush cim -y --partial --source=modules/contrib/commerce_recurring/config/install;

Step 4: clear cache

Step 5: Then try to uninstall commerce_recurring

I confirm that this has worked for me. If someone can review the latest patch in this issue queue and we can get it committed into core, I will gladly write the patch for #2924965: [PP-1] Module does not uninstall cleanly (dependency issue)

zenimagine’s picture

Thanks for the explanations, I will wait for a patch because it seems very complicated. It's been 2 years since I made the mistake of installing this module on my production site and could not uninstall it. I can't wait to get rid of it.

xamount’s picture

Status: Needs review » Reviewed & tested by the community

I am going to set the status to RTBC. Feel free to change it back to "Needs Review".

jungle’s picture

Issue tags: +Needs tests

Needs tests or I am afraid that it won't be committed.

jungle’s picture

Status: Reviewed & tested by the community » Needs work
colan’s picture

See #10.

nattyweb’s picture

xamount's advice in #34 looked promising for me after following the instructions carefully. Until, that is, I reached step 4, at which point I got this after issuing the drush cache:rebuild (and also the error "the website encountered an unexpected error. Please try again later." on the site):

In FieldStorageConfigStorage.php line 174:
                                                                                                                 
  Unable to determine class for field type 'commerce_plugin_item:commerce_subscription_type' found in the 'fiel  
  d.storage.commerce_product_variation.subscription_type' configuration                                                                                                                                                           

In DiscoveryTrait.php line 53:
                                                                                                                 
  The "commerce_plugin_item:commerce_subscription_type" plugin does not exist. Valid plugin IDs for Drupal\Core  
  \Field\FieldTypePluginManager are: address_zone, address_country, address, comment, commerce_remote_id, comme  
  rce_plugin_item:commerce_condition, commerce_plugin_item:commerce_promotion_offer, commerce_plugin_item:comme  
  rce_license_type, commerce_plugin_item:recurring_period, commerce_adjustment, commerce_price, datetime, entit  
  y_reference_revisions, feeds_item, file, file_uri, fontawesome_icon, image, interval, layout_section, link, m  
  etatag, list_string, list_float, list_integer, path, redirect_source, state, text_long, text_with_summary, te  
  xt, viewsreference, webform, xfloat, xinteger, xdecimal, xquantity_stock, email, uuid, string_long, changed,   
  password, float, timestamp, language, integer, boolean, decimal, uri, map, string, entity_reference, created   

So I guess it's not possible, unless I did something wrong (or have a peculiar setup).

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

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

mohit_aghera’s picture

Status: Needs work » Needs review
Issue tags: -Needs tests
StatusFileSize
new7.39 KB
new5.41 KB
new6.19 KB

Adding test cases with simple entity and field plugin.
For the testing i've included configuration which has "enforced" key in it.

enforced:
    module:
      - entity_uninstall_validator

Status: Needs review » Needs work

The last submitted patch, 39: test-only-2871486-39.patch, failed testing. View results

mohit_aghera’s picture

Status: Needs work » Needs review
StatusFileSize
new7.38 KB
new5.4 KB
new795 bytes

Fixing test case failures related to the field storage configuration yml file.
I've updated test-only file as well.

Status: Needs review » Needs work

The last submitted patch, 41: test-only-2871486-41.patch, failed testing. View results

mohit_aghera’s picture

Status: Needs work » Needs review

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

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now 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.4.x-dev » 9.5.x-dev

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now 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.

rivimey’s picture

Bump:

Given this affects commerce_recurring directly, and there is a patch is there any scope for a resolution to this soon?

quietone’s picture

Issue summary: View changes
Issue tags: +Bug Smash Initiative

This was a Bug Smash random triage issue. I was wondering if this was works as designed but darvanen disagreed. Updated the remaining tasks to indicate this Needs review.

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

Drupal 9.5.0-beta2 and Drupal 10.0.0-beta2 were released on September 29, 2022, which means new developments and disruptive changes should now be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

needs-review-queue-bot’s picture

Status: Needs review » Needs work
StatusFileSize
new154 bytes

The Needs Review Queue Bot tested this issue. It either no longer applies to Drupal core, or fails the Drupal core commit checks. Therefore, this issue status is now "Needs work".

Apart from a re-roll or rebase, this issue may need more work to address feedback in the issue or MR comments. To progress an issue, incorporate this feedback as part of the process of updating the issue. This helps other contributors to know what is outstanding.

Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.

joshuautley’s picture

@rivimey #46 following up on this as it relates to commerce_recurring.

Has anyone used the patch in #41 successfully in this use case?

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.

jmagunia’s picture

StatusFileSize
new5.4 KB

Even after the patch in #41 Commerce Recurring fails upon uninstall for me:

commerce_recurring: The <em class="placeholder">Billing period</em> field type is used in the following fields: commerce_order.billing_period, commerce_order_item.billing_period

I haven't had much luck uninstalling Commerce Core either.

Version: 11.x-dev » main

Drupal core is now using the main branch as the primary development branch. New developments and disruptive changes should now be targeted to the main branch.

Read more in the announcement.