- 🇧🇪Belgium lorenzs
This is a fix on a deprecated function.
setAccount will be removed in the upcoming D10 release
A fatal error occurs when the context key "user" is present but this has a value which is anything other than an object that implements AccountInterface
. It is not guaranteed that the "user" context key is an account object at all times. We should check the type beforehand.
This can be easily reproduced by installing the Monolog module, and logging in. The Monolog module includes a CurrentUserProcessor
which provides a "user" context key which is not a full user object but instead a string containing the user name.
The following error occurs:
Error: Call to a member function id() on string in Drupal\jsonlog\Logger\JsonLogData->setAccount() (line 167 of /app/docroot/modules/contrib/jsonlog/src/Logger/JsonLogData.php).
Drupal\jsonlog\Logger\JsonLogData->setAccount('admin@migros.dummy') (Line: 192)
Drupal\jsonlog\Logger\JsonLog->prepareLog(3, 'Error: Call to a member function id() on string in Drupal\jsonlog\Logger\JsonLogData->setAccount() (line 167 of /app/docroot/modules/contrib/jsonlog/src/Logger/JsonLogData.php) #0 /app/docroot/modules/contrib/jsonlog/src/Logger/JsonLog.php(192): Drupal\jsonlog\Logger\JsonLogData->setAccount('admin@migros.du...')
#1 /app/docroot/modules/contrib/jsonlog/src/Logger/JsonLog.php(125): Drupal\jsonlog\Logger\JsonLog->prepareLog(5, 'Session opened ...', Array)
#2 /app/docroot/modules/contrib/monolog/src/Logger/Handler/DrupalHandler.php(60): Drupal\jsonlog\Logger\JsonLog->log(5, 'Session opened ...', Array)
#3 /app/vendor/monolog/monolog/src/Monolog/Handler/AbstractProcessingHandler.php(48): Drupal\monolog\Logger\Handler\DrupalHandler->write(Array)
#4 /app/vendor/monolog/monolog/src/Monolog/Logger.php(327): Monolog\Handler\AbstractProcessingHandler->handle(Array)
#5 /app/docroot/modules/contrib/monolog/src/Logger/Logger.php(46): Monolog\Logger->addRecord(250, 'Session opened ...', Array)
#6 /app/vendor/monolog/monolog/src/Monolog/Logger.php(539): Drupal\monolog\Logger\Logger->addRecord(250, 'Session opened ...', Array)
#7 /app/docroot/core/modules/user/user.module(456): Monolog\Logger->notice('Session opened ...', Array)
Check that the data is of the correct type before passing it to the method.
Closed: won't fix
3.0
Code
Not all content is available!
It's likely this issue predates Contrib.social: some issue and comment data are missing.
This is a fix on a deprecated function.
setAccount will be removed in the upcoming D10 release