"Adding non-existent permissions to a role is not allowed." error

Created on 3 January 2025, 3 months ago

Upgraded to 3.0.0 on D10.4.0 and on running database updates I got

RuntimeException: Adding non-existent permissions to a role is not allowed. The incorrect permissions are "delete files". in Drupal\user\Entity\Role->calculateDependencies() (line 216 of core\modules\user\src\Entity\Role.php).

Drupal\Core\Config\Entity\ConfigEntityBase->preSave(Object) (Line: 183)
Drupal\user\Entity\Role->preSave(Object) (Line: 528)
Drupal\Core\Entity\EntityStorageBase->doPreSave(Object) (Line: 483)
Drupal\Core\Entity\EntityStorageBase->save(Object) (Line: 257)
Drupal\Core\Config\Entity\ConfigEntityStorage->save(Object) (Line: 354)
Drupal\Core\Entity\EntityBase->save() (Line: 617)
Drupal\Core\Config\Entity\ConfigEntityBase->save() (Line: 1010)
user_role_grant_permissions('admi', Array) (Line: 984)
user_role_change_permissions('admi', Array) (Line: 257)
Drupal\user\Form\UserPermissionsForm->submitForm(Array, Object)
call_user_func_array(Array, Array) (Line: 129)
Drupal\Core\Form\FormSubmitter->executeSubmitHandlers(Array, Object) (Line: 67)
Drupal\Core\Form\FormSubmitter->doSubmitForm(Array, Object) (Line: 597)
Drupal\Core\Form\FormBuilder->processForm('user_admin_permissions', Array, Object) (Line: 326)
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: 638)
Drupal\Core\Render\Renderer->executeInRenderContext(Object, Object) (Line: 121)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext(Array, Array) (Line: 97)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 181)
Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object, 1) (Line: 76)
Symfony\Component\HttpKernel\HttpKernel->handle(Object, 1, 1) (Line: 53)
Drupal\Core\StackMiddleware\Session->handle(Object, 1, 1) (Line: 48)
Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object, 1, 1) (Line: 28)
Drupal\Core\StackMiddleware\ContentLength->handle(Object, 1, 1) (Line: 32)
Drupal\big_pipe\StackMiddleware\ContentLength->handle(Object, 1, 1) (Line: 116)
Drupal\page_cache\StackMiddleware\PageCache->pass(Object, 1, 1) (Line: 90)
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: 36)
Drupal\Core\StackMiddleware\AjaxPageState->handle(Object, 1, 1) (Line: 51)
Drupal\Core\StackMiddleware\StackedHttpKernel->handle(Object, 1, 1) (Line: 741)
Drupal\Core\DrupalKernel->handle(Object) (Line: 19)

According to this πŸ› "Adding non-existent permissions to a role is not allowed." exception is thrown for profile installations Needs work , β€œThe module that defines the permission is responsible for defining the dependencies.” I tried the patch β†’ there, but it didn’t help.

πŸ› Bug report
Status

Active

Version

3.0

Component

Code

Created by

πŸ‡­πŸ‡ΊHungary Grabby

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

Merge Requests

Comments & Activities

  • Issue created by @Grabby
  • πŸ‡³πŸ‡±Netherlands arantxio Dordrecht

    I am also experiencing this issue at the moment, i think the check needs to be changed to "delete any file" instead of "delete files", as it seems this permission doesn't exist. But since we already check for "delete own files" and "delete any files" it can be dropped in general

  • Pipeline finished with Success
    3 months ago
    Total: 153s
    #387419
  • πŸ‡³πŸ‡±Netherlands arantxio Dordrecht

    I've created the above merge request, it worked for me on the first time, but I tried it again and now it doesn't seem to work, so ill have to adjust something first.

  • Pipeline finished with Success
    3 months ago
    Total: 143s
    #387442
  • πŸ‡³πŸ‡±Netherlands arantxio Dordrecht

    I have updated the code to fix the error the problem is the previous code checks for the permission "delete file" but this permission didn't exist, it used to be "delete files" which is the permission its missing because it got removed in the upgrade to 3.0

    The merge request fixes the "file_delete_update_400002" update hook to look for the other permission.

    This solves the upgrade problem I had.

  • πŸ‡³πŸ‡±Netherlands arantxio Dordrecht
  • First commit to issue fork.
  • πŸ‡¨πŸ‡¦Canada man-1982

    all good.
    Works as designed.
    thanks @arantxio

  • πŸ‡§πŸ‡·Brazil astutonet Sao Paulo, SP

    I've also been having this issue on a website.

    I initially updated to version 3.0.0 using D10.4.1. However, it was not possible to update the database.

    I then downloaded version 3.0.x-dev and when I tried to update the database, the problem repeated itself.

    I checked the users' permissions to delete files and tried to remove the permission for authenticated users, but it was not possible.

    Looking at the log messages, I see the following errors:

    Database Update:

    module file_delete
    Update 400003

    Failed: RuntimeException: Adding non-existent permissions to a role is not allowed. The incorrect permissions are "delete files". in function Drupal\user\Entity\Role->calculateDependencies() (line 210 of file /home/username/domains/domain.name.com/public_html/core/modules/user/src/Entity/Role.php).

    Recent Log Messages:

    #0 /home/username/domains/domain.name.com/public_html/core/lib/Drupal/Core/Config/Entity/ConfigEntityBase.php(328): Drupal\user\Entity\Role->calculateDependencies()
    #1 /home/username/domains/domain.name.com/public_html/core/modules/user/src/Entity/Role.php(182): Drupal\Core\Config\Entity\ConfigEntityBase->preSave()
    #2 /home/username/domains/domain.name.com/public_html/core/lib/Drupal/Core/Entity/EntityStorageBase.php(528): Drupal\user\Entity\Role->preSave()
    #3 /home/username/domains/domain.name.com/public_html/core/lib/Drupal/Core/Entity/EntityStorageBase.php(483): Drupal\Core\Entity\EntityStorageBase->doPreSave()
    #4 /home/username/domains/domain.name.com/public_html/core/lib/Drupal/Core/Config/Entity/ConfigEntityStorage.php(257): Drupal\Core\Entity\EntityStorageBase->save()
    #5 /home/username/domains/domain.name.com/public_html/core/lib/Drupal/Core/Entity/EntityBase.php(354): Drupal\Core\Config\Entity\ConfigEntityStorage->save()
    #6 /home/username/domains/domain.name.com/public_html/core/lib/Drupal/Core/Config/Entity/ConfigEntityBase.php(617): Drupal\Core\Entity\EntityBase->save()
    #7 /home/username/domains/domain.name.com/public_html/core/modules/user/user.module(1031): Drupal\Core\Config\Entity\ConfigEntityBase->save()
    #8 /home/username/domains/domain.name.com/public_html/core/modules/user/user.module(989): user_role_revoke_permissions()
    #9 /home/username/domains/domain.name.com/public_html/core/modules/user/src/Form/UserPermissionsForm.php(257): user_role_change_permissions()
    #10 [internal function]: Drupal\user\Form\UserPermissionsForm->submitForm()
    #11 /home/username/domains/domain.name.com/public_html/core/lib/Drupal/Core/Form/FormSubmitter.php(129): call_user_func_array()
    #12 /home/username/domains/domain.name.com/public_html/core/lib/Drupal/Core/Form/FormSubmitter.php(67): Drupal\Core\Form\FormSubmitter->executeSubmitHandlers()
    #13 /home/username/domains/domain.name.com/public_html/core/lib/Drupal/Core/Form/FormBuilder.php(597): Drupal\Core\Form\FormSubmitter->doSubmitForm()
    #14 /home/username/domains/domain.name.com/public_html/core/lib/Drupal/Core/Form/FormBuilder.php(326): Drupal\Core\Form\FormBuilder->processForm()
    #15 /home/username/domains/domain.name.com/public_html/core/lib/Drupal/Core/Controller/FormController.php(73): Drupal\Core\Form\FormBuilder->buildForm()
    #16 [internal function]: Drupal\Core\Controller\FormController->getContentResult()
    #17 /home/username/domains/domain.name.com/public_html/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(123): call_user_func_array()
    #18 /home/username/domains/domain.name.com/public_html/core/lib/Drupal/Core/Render/Renderer.php(638): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}()
    #19 /home/username/domains/domain.name.com/public_html/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(121): Drupal\Core\Render\Renderer->executeInRenderContext()
    #20 /home/username/domains/domain.name.com/public_html/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(97): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext()
    #21 /home/username/domains/domain.name.com/public_html/vendor/symfony/http-kernel/HttpKernel.php(181): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}()
    #22 /home/username/domains/domain.name.com/public_html/vendor/symfony/http-kernel/HttpKernel.php(76): Symfony\Component\HttpKernel\HttpKernel->handleRaw()
    #23 /home/username/domains/domain.name.com/public_html/core/lib/Drupal/Core/StackMiddleware/Session.php(53): Symfony\Component\HttpKernel\HttpKernel->handle()
    #24 /home/username/domains/domain.name.com/public_html/core/lib/Drupal/Core/StackMiddleware/KernelPreHandle.php(48): Drupal\Core\StackMiddleware\Session->handle()
    #25 /home/username/domains/domain.name.com/public_html/core/lib/Drupal/Core/StackMiddleware/ContentLength.php(28): Drupal\Core\StackMiddleware\KernelPreHandle->handle()
    #26 /home/username/domains/domain.name.com/public_html/core/modules/big_pipe/src/StackMiddleware/ContentLength.php(32): Drupal\Core\StackMiddleware\ContentLength->handle()
    #27 /home/username/domains/domain.name.com/public_html/core/modules/page_cache/src/StackMiddleware/PageCache.php(116): Drupal\big_pipe\StackMiddleware\ContentLength->handle()
    #28 /home/username/domains/domain.name.com/public_html/core/modules/page_cache/src/StackMiddleware/PageCache.php(90): Drupal\page_cache\StackMiddleware\PageCache->pass()
    #29 /home/username/domains/domain.name.com/public_html/core/modules/ban/src/BanMiddleware.php(50): Drupal\page_cache\StackMiddleware\PageCache->handle()
    #30 /home/username/domains/domain.name.com/public_html/core/lib/Drupal/Core/StackMiddleware/ReverseProxyMiddleware.php(48): Drupal\ban\BanMiddleware->handle()
    #31 /home/username/domains/domain.name.com/public_html/core/lib/Drupal/Core/StackMiddleware/NegotiationMiddleware.php(51): Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle()
    #32 /home/username/domains/domain.name.com/public_html/core/lib/Drupal/Core/StackMiddleware/AjaxPageState.php(36): Drupal\Core\StackMiddleware\NegotiationMiddleware->handle()
    #33 /home/username/domains/domain.name.com/public_html/core/lib/Drupal/Core/StackMiddleware/StackedHttpKernel.php(51): Drupal\Core\StackMiddleware\AjaxPageState->handle()
    #34 /home/username/domains/domain.name.com/public_html/core/lib/Drupal/Core/DrupalKernel.php(741): Drupal\Core\StackMiddleware\StackedHttpKernel->handle()
    #35 /home/username/domains/domain.name.com/public_html/index.php(19): Drupal\Core\DrupalKernel->handle()
    #36 {main}

    Can someone help us, pls? Tks!

  • πŸ‡§πŸ‡·Brazil astutonet Sao Paulo, SP
  • πŸ‡©πŸ‡ͺGermany kreatIL

    I am experiencing the same issue as described here. I have tested this with the latest 3.x-dev version of the module, but the problem persists. Drupal 10.3.10 in my usecase.

    Additionally, I have created a patch based on the changes provided in commit #6 and applied it to my site. Unfortunately, the error still occurs after applying the patch.

    Updating the status of this issue to "needs work"

  • πŸ‡§πŸ‡ͺBelgium flyke

    I have no idea why this patch does not work.
    It applies.
    I can see in web/modules/contrib/file_delete/file_delete.install inside file_delete_update_400003() that there is absolutely no 'delete files' in that code. Yet, if I try running drush updb -y, then I always get the error

    >  [notice] Update started: file_delete_update_400003
    >  [error]  Adding non-existent permissions to a role is not allowed. The incorrect permissions are "delete files". 
    >  [error]  Update failed: file_delete_update_400003 

    It makes no sense. I cleared caches multiple times, I restarted my local project, I emptied cache tables, I do not get why the error references a problem with 'delete files' whle that is not literally in the code

    function file_delete_update_400003(): void {
      $roles = Role::loadMultiple();
      foreach ($roles as $role) {
        if ($role->hasPermission('delete own files') || $role->hasPermission('delete any files')) {
          $role->grantPermission('delete files override usage');
          $role->grantPermission('delete files immediately');
          $role->save();
        }
      }
    }

    So to fix this, I just exported my config using drush cex -y, then I searched in my config folder for delete files, which was inside a user.role.somerolename.yml file. I deleted that line and imported my config using drush cim -y and after that I had no problem running drush updb -y. Lastly, I edited the role via the admin UI to give back the delete files permissions.

  • πŸ‡©πŸ‡ͺGermany kreatIL

    I have implemented the solution outlined in comment #12 and can confirm that it successfully bypasses the error message, allowing updb to run without any issues.

  • πŸ‡³πŸ‡±Netherlands arantxio Dordrecht

    The problem lies in the fact that you probably already ran the updb script before adding the patch, as you found out about it later, i've added it in such a way that it has to run the previous updates first.

    The workaround you mentioned also works yes, remove the permission directly from the config, you can do this if you already ran the updb scripts before adding the updated patch.

  • πŸ‡³πŸ‡±Netherlands arantxio Dordrecht

    Here is a patch for people that already ran the previous update, this should edit the permission table so you dont have any problems.

    Let me know if it works for you as I don't have project to test it on anymore.

    P.S. this is not the official fix! The official fix is the merge request, as it should be fixed in the main branch before people are actually updating.

  • πŸ‡§πŸ‡ͺBelgium fernly

    This is a static patch of the current approved merge request for people wanting to add it to there project.

  • πŸ‡ΊπŸ‡ΏUzbekistan biarr

    #16 is Solving the issue. Thanks!

  • πŸ‡ΊπŸ‡ΈUnited States laura.gates

    I'm also getting the following error upgrading to v3.0.0 with Drupal 10.4.x

    > [error] /var/www/html/docroot/modules/contrib/file_delete/file_delete.permissions.yml: Duplicate key "delete files override usage" detected at line 11.
    > [error] Update failed: file_delete_update_400002
    [error] Update aborted by: block_class_update_20017, file_delete_update_400002
    [error] Finished performing updates.

    I applied patch #16 and it is successful.

  • Status changed to RTBC 29 days ago
  • πŸ‡ΊπŸ‡ΈUnited States laura.gates
  • πŸ‡©πŸ‡ͺGermany Duwid

    The error also occurs with the delete files settings permission. In my case, the admin role had this permission. I was able to fix it by revoking the permission manually before running the database update, but this should be handled by the update hook.

  • πŸ‡©πŸ‡ͺGermany Duwid
Production build 0.71.5 2024