Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Weprofiler module throws fatal error when the module is enabled and a user is logged in using the admin (user id 1), because there are no roles assigned to that role.
The website encountered an unexpected error. Please try again later.
Error: Call to a member function label() on null in Drupal\webprofiler\DataCollector\UserDataCollector->collect() (line 66 of modules/contrib/devel/webprofiler/src/DataCollector/UserDataCollector.php).
Drupal\webprofiler\DataCollector\UserDataCollector->collect(Object, Object, NULL) (Line: 223)
Symfony\Component\HttpKernel\Profiler\Profiler->collect(Object, Object, NULL) (Line: 128)
Symfony\Component\HttpKernel\EventListener\ProfilerListener->onKernelResponse(Object, 'kernel.response', Object)
call_user_func(Array, Object, 'kernel.response', Object) (Line: 61)
Symfony\Component\EventDispatcher\Debug\WrappedListener->__invoke(Object, 'kernel.response', Object) (Line: 111)
Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher->dispatch('kernel.response', Object) (Line: 140)
Symfony\Component\EventDispatcher\Debug\TraceableEventDispatcher->dispatch('kernel.response', Object) (Line: 184)
Symfony\Component\HttpKernel\HttpKernel->filterResponse(Object, Object, 1) (Line: 166)
Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object, 1) (Line: 64)
Symfony\Component\HttpKernel\HttpKernel->handle(Object, 1, 1) (Line: 57)
Drupal\Core\StackMiddleware\Session->handle(Object, 1, 1) (Line: 47)
Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object, 1, 1) (Line: 99)
Drupal\page_cache\StackMiddleware\PageCache->pass(Object, 1, 1) (Line: 78)
Drupal\page_cache\StackMiddleware\PageCache->handle(Object, 1, 1) (Line: 47)
Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object, 1, 1) (Line: 43)
Drupal\webprofiler\StackMiddleware\WebprofilerMiddleware->handle(Object, 1, 1) (Line: 50)
Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object, 1, 1) (Line: 23)
Stack\StackedHttpKernel->handle(Object, 1, 1) (Line: 652)
Drupal\Core\DrupalKernel->handle(Object) (Line: 19)
Comment | File | Size | Author |
---|---|---|---|
#9 | null-role-entity-2830870-9.patch | 966 bytes | malcomio |
| |||
#2 | admin_user-2830870.patch | 808 bytes | abhigupta |
Comments
Comment #2
abhigupta CreditAttribution: abhigupta commentedComment #3
lussolucaYes you are right, only standard profile adds a role to user 1 (in Core).
Just a quick nitpick
Please avoid single equals sign in if condition because it can confuse readers.
Comment #4
lussolucaComment #5
lussolucaUhm..wait,
user 1 should have at least "Authenticated User" role.
Also if code enter in foreach at line 64 the user has at least a role. In your case it seems that the user has a role that no longer exists (so the load() returns NULL).
Could you please check if this is the case?
Comment #6
kdebisschop CreditAttribution: kdebisschop as a volunteer commentedThis is not only a problem with user/1 - it seems to be a problem with any user that has only the authenticated role. Adding an essentially unprivileged role makes it work.
Comment #7
twfahey CreditAttribution: twfahey as a volunteer commented#2 fixed it for me, from my investigation it appears that 'administrator' loads as NULL when piped through ` $entity = $storage->load($role); `. I can tell you that this was on a clean install, however it was using a custom installation profile. I haven't tested it with a vanilla D8 install, but I don't believe I'm altering anything in regards to roles, I'm really just enabling a theme and some modules. Before I found this issue, I was ksm'ing on `$this->currentUser->getRoles()`, which tells me my user has only the 2 roles:
```
string(13) "authenticated"
string(13) "administrator"
```
When I ksm'ed inside the loop ~line 66, that's when I discovered that the authenticated role was loading, but administrator was not, it was null.
Comment #8
Rar9 CreditAttribution: Rar9 commentedapplying patch reduced error but I now get
Warning: Invalid argument supplied for foreach() in Drupal\webprofiler\EventDispatcher\TraceableEventDispatcher->addCalledListener() (line 166 of /var/www/vhosts/XXXX/httpdocs/modules/devel/webprofiler/src/EventDispatcher/TraceableEventDispatcher.php).
Comment #9
malcomio CreditAttribution: malcomio as a volunteer and at Capgemini commentedI'm also getting this error with a custom install profile.
Stepping through this in XDebug for user 1, $storage->entities contains a Role object for 'authenticated', but null for 'administrator'.
Seems likely to be a symptom of another issue somewhere else - probably related to the fact that the config yml for the administrator role is in the standard install profile.
We could at least prevent the fatal error by checking if the entity exists, and using the role ID if not.
Comment #10
malcomio CreditAttribution: malcomio as a volunteer and at Capgemini commentedI think (at least in our case) that the role entity is null because the custom install profile calls standard_install(), as suggested on https://www.drupal.org/docs/8/creating-distributions/how-to-write-a-drup...
This includes assigning the administrator role to user 1, but because the config for the role is defined in the standard profile, the role entity is not created.
Might also be worth testing with the minimal install profile.
Comment #11
malcomio CreditAttribution: malcomio as a volunteer and at Capgemini commentedHaving investigated further, this is indeed happening because the custom install profile does not include config for the administrator role.
The wiki page mentions that it was written based on the Spark profile, which does include the role config .
Adding the config to our custom profile means that the entity exists, and the error no longer occurs (with or without the patch applied).
I think that the custom profile documentation should be updated to mention this.
Comment #12
Prashant.c@abhigupta
How is this possible that User 1 does not have any role.
He will always have 2 roles "authenticated" and "administrator" and even if you remove "administrator" he will always have "authenticated" role.
Can you please list down the steps how can i replicate this ?
Comment #13
salvisThank you for the research, malcomio.
This seems to be a rare issue, likely tied to buggy installation profiles. Has anyone been able to reproduce it with plain vanilla D8?
Comment #14
willzyx CreditAttribution: willzyx commentedClosing for lack of activity. Feel free to reopen if the issue still exists