Role::getPermissions() returns empty array in Drupal 10.4.8 with is_admin: false

Created on 11 June 2025, 28 days ago

Title: Role::getPermissions() returns empty array in Drupal 10.4.8 with is_admin: false

Project: Drupal core

Version: 10.4.8

Component: User module

Category: Bug report

Priority: Normal

Steps Required to Reproduce the Bug:

Install Drupal 10.4.8.
Configure the administrator role with specific permissions (e.g., access administration pages, access content overview, access toolbar, administer content types, administer node fields, administer site configuration, view the administration theme).
Set is_admin: true for the administrator role using:
bash

Collapse

Wrap

Run

Copy
drush config:set user.role.administrator is_admin true
drush cache:rebuild
Test getPermissions():
bash

Collapse

Wrap

Run

Copy
drush php-eval "var_dump(\Drupal::entityTypeManager()->getStorage('user_role')->load('administrator')->getPermissions());"
Set is_admin: false:
bash

Collapse

Wrap

Run

Copy
drush config:set user.role.administrator is_admin false
drush cache:rebuild
Re-test getPermissions() using the same command.
Compare with toArray()['permissions'] and role_permission table:
bash

Collapse

Wrap

Run

Copy
drush php-eval "var_dump(\Drupal::entityTypeManager()->getStorage('user_role')->load('administrator')->toArray()['permissions']);"
mysql -u -p -e "SELECT permission FROM role_permission WHERE rid = 'administrator'"
Test hasPermission() for a user with the administrator role:
bash

Collapse

Wrap

Run

Copy
drush php-eval "var_dump(\Drupal::entityTypeManager()->getStorage('user')->load(1)->hasPermission('access administration pages'));"
What Behavior Were You Expecting?:

With is_admin: true, getPermissions() may return an empty array (as per Drupal’s optimization for administrator roles).
With is_admin: false, getPermissions() should return the assigned permissions (e.g., the 7 permissions listed above).
toArray()['permissions'] and role_permission table should match getPermissions() when is_admin: false.
hasPermission() should return true for assigned permissions.
What Happened Instead?:

With is_admin: true, getPermissions() returns array(0) [], which aligns with Drupal’s design.
With is_admin: false, getPermissions() still returns array(0) [], which is incorrect.
toArray()['permissions'] and role_permission table correctly list the 7 assigned permissions.
hasPermission() returns bool(true) for assigned permissions, confirming functionality.
All permissions are defined in \Drupal::service('user.permissions')->getPermissions().
System Information:

OS: Ubuntu (inferred from prompt).
Webserver: Apache (assumed, common for Drupal).
PHP Version: 8.1+ (required by Drupal 10.4.8, exact version unknown).
Drupal Version: 10.4.8.
Drupal Path: /var/www/drupal.
Database: MySQL, user drupalmain, database drupal_main.
Modules: Commerce modules partially uninstalled, core modules enabled.
Additional Notes:
No migration issues (no Drupal 7 history).
Cache cleared after every change.
No PHP errors in logs (assumed, no WSOD reported).
No pending database updates (drush updatedb reported no updates).
Proposed Solution:

Investigate Drupal\user\Entity\Role::getPermissions() to ensure it returns assigned permissions when is_admin: false.
Verify permission validation and caching logic in the user module.

🐛 Bug report
Status

Active

Version

10.4

Component

user.module

Created by

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

Comments & Activities

  • Issue created by @adminbfe
  • The issue summary needs reformatting to be understandable. Are you saying this is a regression in 10.4.8 as compared to a prior version of Drupal? If so, then which version worked?

Production build 0.71.5 2024