Problem/Motivation

Module configurations are not removed properly during uninstall. Getting error bellow error on install module.

Unable to install Avatar Kit, field.field.user.user.avatars_avatar_generator, field.storage.user.avatars_avatar_generator already exist in active configuration.

Steps to reproduce

  1. Install Avatar Kit as normal
  2. Uninstall the module
  3. Try to install module again
  4. During install the error will throw and not allowing to install.

Proposed resolution

Implement hook_uninstall() to remove configuration.

Remaining tasks

Nil

User interface changes

Nil

API changes

Nil

Data model changes

Nil

Re-install issue

Issue fork avatars-3294517

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

arunkumark created an issue. See original summary.

arunkumark’s picture

Status: Active » Needs review
StatusFileSize
new602 bytes
dpi’s picture

Status: Needs review » Needs work
Issue tags: -installation problems, -configuration

The config should probably just be moved to optional.

joachim’s picture

> The config should probably just be moved to optional.

Not sure that's the right fix.

The module should clean up after itself and delete the field -- because otherwise, going to admin/config/people/accounts/fields/user.user.avatars_avatar_generator crashes the site because the options provider is no longer available.

joachim’s picture

Priority: Major » Critical
+++ b/avatars.install
@@ -15,3 +15,13 @@ function avatars_install() {
+  // Remove configuration related to Avatar module.

We don't need to do this in an uninstall hook AFAIK -- should be able to do this by setting a config dependency on the fields created in hook_install().

And there is also the avatars_user_picture field to clean up similarly.

socialnicheguru’s picture

This is needed as avatar persists in other config entities on the site after deletion.

socialnicheguru’s picture

Will the current patch delete these fields too:
field.field.user.user.avatars_user_picture.yml
field.storage.user.avatars_user_picture.yml

also references are added to a number of other configs.
When I uninstalled I thought that the references to avatars would be removed but it was not.

joachim’s picture

> This is needed as avatar persists in other config entities on the site after deletion.

That is handled automatically by the config system if dependencies are correctly declared.

See ConfigEntityBase;:onDependencyRemoval().

socialnicheguru’s picture

it is not happening.

So how can I debug and trace dependencies to isolate the issue

socialnicheguru’s picture

Status: Needs work » Needs review
StatusFileSize
new733 bytes

rerolled and added user.avatars_user_picture which persists after uninstall with the previous patch.

coaston’s picture

Patch works fine.

However it works to uninstall module correctly. However who already uninstalled it first need to remove fields manually and then install module again:

/admin/config/people/accounts/fields

-remove avatars_avatar_generator and avatars_user_picture manually
-refresh cache
-install module again
-uninstall module again - works.

coaston’s picture

Status: Needs review » Active

Another issue discovered > you cannot unisntall module if there is any role permission already assigned to submodules (i uninstalled Robot submodule and then tried to unisntall this one). However below config should be removed from robot submodule. :

Note: robot2 and robot were names of my generator.

RuntimeException: Adding non-existent permissions to a role is not allowed. The incorrect permissions are "avatars avatar_generator user robot", "avatars avatar_generator user robot2". in Drupal\user\Entity\Role->calculateDependencies() (line 207 of core\modules\user\src\Entity\Role.php).
Drupal\Core\Config\ConfigManager->getConfigEntitiesToChangeOnDependencyRemoval('module', Array) (Line: 43)
Drupal\system\Form\ModulesUninstallConfirmForm->addDependencyListsToForm(Array, 'module', Array, Object, Object) (Line: 160)
Drupal\system\Form\ModulesUninstallConfirmForm->buildForm(Array, Object)
call_user_func_array(Array, Array) (Line: 536)
Drupal\Core\Form\FormBuilder->retrieveForm('system_modules_uninstall_confirm_form', Object) (Line: 283)
Drupal\Core\Form\FormBuilder->buildForm(Object, Object) (Line: 73)
Drupal\Core\Controller\FormController->getContentResult(Object, Object)
call_user_func_array(Array, Array) (Line: 123)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 583)
Drupal\Core\Render\Renderer->executeInRenderContext(Object, Object) (Line: 124)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext(Array, Array) (Line: 97)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 182)
Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object, 1) (Line: 76)
Symfony\Component\HttpKernel\HttpKernel->handle(Object, 1, 1) (Line: 58)
Drupal\Core\StackMiddleware\Session->handle(Object, 1, 1) (Line: 48)
Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object, 1, 1) (Line: 106)
Drupal\page_cache\StackMiddleware\PageCache->pass(Object, 1, 1) (Line: 85)
Drupal\page_cache\StackMiddleware\PageCache->handle(Object, 1, 1) (Line: 48)
Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object, 1, 1) (Line: 51)
Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object, 1, 1) (Line: 51)
Drupal\Core\StackMiddleware\StackedHttpKernel->handle(Object, 1, 1) (Line: 704)
Drupal\Core\DrupalKernel->handle(Object) (Line: 19)
shevgeny’s picture

I can't delete the module, I can't disable the permission to upload avatars for the user role. Error:

RuntimeException: Adding non-existent permissions to a role is not allowed. The incorrect permissions are "avatars avatar_generator user gravatar", "avatars avatar_generator user gravatar_generator", "avatars avatar_generator user robohash". in Drupal\user\Entity\Role->calculateDependencies() (line 207 of /web/core/modules/user/src/Entity/Role.php).

The patches did not help. Drupal 10.2, module 8.x-2.x-dev, PHP 8.1.