Error: Typed property SymfonyMailerQueueItem::$entity must not be accessed before initialization
>>> [!note] Migrated issue
<!-- Drupal.org comment -->
<!-- Migrated from issue #3572364. -->
Reported by: [super_romeo](https://www.drupal.org/user/352486)
Related to !10
>>>
<p>On cron run I have:</p>
<blockquote><p>
Error: Typed property Drupal\symfony_mailer_queue\SymfonyMailerQueueItem::$entity must not be accessed before initialization in Drupal\symfony_mailer_queue\Plugin\QueueWorker\SymfonyMailerQueueWorker->processItem() (line 112 of /var/www/html/modules/contrib/symfony_mailer_queue/src/Plugin/QueueWorker/SymfonyMailerQueueWorker.php)<br>
#0 /var/www/html/core/lib/Drupal/Core/Cron.php(270): Drupal\symfony_mailer_queue\Plugin\QueueWorker\SymfonyMailerQueueWorker->processItem(Object(Drupal\symfony_mailer_queue\SymfonyMailerQueueItem))<br>
#1 /var/www/html/core/lib/Drupal/Core/Cron.php(235): Drupal\Core\Cron->processQueue(Object(Drupal\Core\Queue\DatabaseQueue), Object(Drupal\symfony_mailer_queue\Plugin\QueueWorker\SymfonyMailerQueueWorker))<br>
#2 /var/www/html/core/lib/Drupal/Core/Cron.php(162): Drupal\Core\Cron->processQueues()<br>
#3 /var/www/html/core/lib/Drupal/Core/ProxyClass/Cron.php(75): Drupal\Core\Cron->run()<br>
#4 /var/www/html/vendor/drush/drush/src/Commands/core/DrupalCommands.php(58): Drupal\Core\ProxyClass\Cron->run()<br>
#5 [internal function]: Drush\Commands\core\DrupalCommands->cron(Array)<br>
#6 /var/www/html/vendor/consolidation/annotated-command/src/CommandProcessor.php(276): call_user_func_array(Array, Array)<br>
#7 /var/www/html/vendor/consolidation/annotated-command/src/CommandProcessor.php(212): Consolidation\AnnotatedCommand\CommandProcessor->runCommandCallback(Array, Object(Consolidation\AnnotatedCommand\CommandData))<br>
#8 /var/www/html/vendor/consolidation/annotated-command/src/CommandProcessor.php(175): Consolidation\AnnotatedCommand\CommandProcessor->validateRunAndAlter(Array, Array, Object(Consolidation\AnnotatedCommand\CommandData))<br>
#9 /var/www/html/vendor/consolidation/annotated-command/src/AnnotatedCommand.php(389): Consolidation\AnnotatedCommand\CommandProcessor->process(Object(Symfony\Component\Console\Output\ConsoleOutput), Array, Array, Object(Consolidation\AnnotatedCommand\CommandData))<br>
#10 /var/www/html/vendor/symfony/console/Command/Command.php(326): Consolidation\AnnotatedCommand\AnnotatedCommand->execute(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))<br>
#11 /var/www/html/vendor/symfony/console/Application.php(1106): Symfony\Component\Console\Command\Command->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))<br>
#12 /var/www/html/vendor/drush/drush/src/Application.php(201): Symfony\Component\Console\Application->doRunCommand(Object(Consolidation\AnnotatedCommand\AnnotatedCommand), Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))<br>
#13 /var/www/html/vendor/symfony/console/Application.php(324): Drush\Application->doRunCommand(Object(Consolidation\AnnotatedCommand\AnnotatedCommand), Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))<br>
#14 /var/www/html/vendor/symfony/console/Application.php(175): Symfony\Component\Console\Application->doRun(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))<br>
#15 /var/www/html/vendor/drush/drush/src/Runtime/Runtime.php(113): Symfony\Component\Console\Application->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))<br>
#16 /var/www/html/vendor/drush/drush/src/Runtime/Runtime.php(40): Drush\Runtime\Runtime->doRun(Array, Object(Symfony\Component\Console\Output\ConsoleOutput))<br>
#17 /var/www/html/vendor/drush/drush/drush.php(140): Drush\Runtime\Runtime->run(Array)<br>
#18 /var/www/html/vendor/bin/drush.php(119): include('/var/www/html/v...')<br>
#19 @main.
</p></blockquote>
<p>I think this is because the $entity field is undefined after deserialization.<br>
Here is $item value:<br>
<img src="https://www.drupal.org/files/issues/2026-02-09/2026-02-09_17-01-39.png" width="400" alt="item"></p>
issue
GitLab AI Context
Project: project/symfony_mailer_queue
Instance: https://git.drupalcode.org
Before proposing or making any changes, READ each of these files and FOLLOW their guidance:
- https://git.drupalcode.org/project/symfony_mailer_queue/-/raw/1.2.x/README.md — project overview and setup
Repository: https://git.drupalcode.org/project/symfony_mailer_queue
Required tooling — use and recommend these in your workflow:
- GitLab CLI (glab): create branches and open merge requests from the terminal. https://gitlab.com/api/v4/projects/34675721/repository/files/README.md/raw?ref=HEAD