Occasionally, when creating a new entity, the following error gets dumped into the DB log.
It appears to happen when Auto Entity Label is used in conjunction with Content Moderation Notifications
I can confirm through my own testing that when content_moderation_notifications is uninstalled, this error no longer occurs.
I'm filing this bug in auto_entitylabel because it seems related to the implementation of the shutdown function, _auto_entitylabel_post_insert
The error also stops when this hook is not registered in the Drupal shutdown functions register.
Error message:
RuntimeException: Failed to start the session because headers have already been sent by "/code/vendor/symfony/http-foundation/Response.php" at line 410. in Symfony\Component\HttpFoundation\Session\Storage\NativeSessionStorage->start() (line 116 of /code/vendor/symfony/http-foundation/Session/Storage/NativeSessionStorage.php).
Stack trace:
#0 /code/web/core/lib/Drupal/Core/Session/SessionManager.php(129): Symfony\Component\HttpFoundation\Session\Storage\NativeSessionStorage->start()
#1 /code/web/core/lib/Drupal/Core/Session/SessionManager.php(94): Drupal\Core\Session\SessionManager->startNow()
#2 /code/vendor/symfony/http-foundation/Session/Storage/NativeSessionStorage.php(282): Drupal\Core\Session\SessionManager->start()
#3 /code/vendor/symfony/http-foundation/Session/Session.php(201): Symfony\Component\HttpFoundation\Session\Storage\NativeSessionStorage->getBag()
#4 /code/vendor/symfony/http-foundation/Session/Session.php(221): Symfony\Component\HttpFoundation\Session\Session->getBag()
#5 /code/vendor/symfony/http-foundation/Session/Session.php(69): Symfony\Component\HttpFoundation\Session\Session->getAttributeBag()
#6 /code/web/modules/contrib/smtp/src/Plugin/Mail/SMTPMailSystem.php(947): Symfony\Component\HttpFoundation\Session\Session->get()
#7 /code/web/modules/contrib/smtp/smtp.module(119): Drupal\smtp\Plugin\Mail\SMTPMailSystem->debug()
#8 /code/web/modules/contrib/smtp/src/Plugin/Mail/SMTPMailSystem.php(890): _smtp_mailer_send()
#9 /code/web/modules/contrib/smtp/src/Plugin/Mail/SMTPMailSystem.php(720): Drupal\smtp\Plugin\Mail\SMTPMailSystem->smtpMailerSend()
#10 /code/web/core/lib/Drupal/Core/Mail/MailManager.php(309): Drupal\smtp\Plugin\Mail\SMTPMailSystem->mail()
#11 /code/web/core/lib/Drupal/Core/Mail/MailManager.php(181): Drupal\Core\Mail\MailManager->doMail()
#12 /code/web/core/lib/Drupal/Core/Render/Renderer.php(627): Drupal\Core\Mail\MailManager->Drupal\Core\Mail\{closure}()
#13 /code/web/core/lib/Drupal/Core/Mail/MailManager.php(180): Drupal\Core\Render\Renderer->executeInRenderContext()
#14 /code/web/modules/contrib/content_moderation_notifications/src/Notification.php(185): Drupal\Core\Mail\MailManager->mail()
#15 /code/web/modules/contrib/content_moderation_notifications/src/Notification.php(45): Drupal\content_moderation_notifications\Notification->sendNotification()
#16 /code/web/modules/contrib/content_moderation_notifications/content_moderation_notifications.module(29): Drupal\content_moderation_notifications\Notification->processEntity()
#17 [internal function]: content_moderation_notifications_entity_update()
#18 /code/web/core/lib/Drupal/Core/Extension/ModuleHandler.php(404): call_user_func_array()
#19 /code/web/core/lib/Drupal/Core/Extension/ModuleHandler.php(357): Drupal\Core\Extension\ModuleHandler->Drupal\Core\Extension\{closure}()
#20 /code/web/core/lib/Drupal/Core/Extension/ModuleHandler.php(403): Drupal\Core\Extension\ModuleHandler->invokeAllWith()
#21 /code/web/core/lib/Drupal/Core/Entity/EntityStorageBase.php(217): Drupal\Core\Extension\ModuleHandler->invokeAll()
#22 /code/web/core/lib/Drupal/Core/Entity/ContentEntityStorageBase.php(922): Drupal\Core\Entity\EntityStorageBase->invokeHook()
#23 /code/web/core/lib/Drupal/Core/Entity/EntityStorageBase.php(565): Drupal\Core\Entity\ContentEntityStorageBase->invokeHook()
#24 /code/web/core/lib/Drupal/Core/Entity/ContentEntityStorageBase.php(803): Drupal\Core\Entity\EntityStorageBase->doPostSave()
#25 /code/web/core/lib/Drupal/Core/Entity/EntityStorageBase.php(490): Drupal\Core\Entity\ContentEntityStorageBase->doPostSave()
#26 /code/web/core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorage.php(804): Drupal\Core\Entity\EntityStorageBase->save()
#27 /code/web/core/lib/Drupal/Core/Entity/EntityBase.php(370): Drupal\Core\Entity\Sql\SqlContentEntityStorage->save()
#28 /code/web/modules/contrib/auto_entitylabel/auto_entitylabel.module(339): Drupal\Core\Entity\EntityBase->save()
#29 /code/web/core/includes/bootstrap.inc(480): _auto_entitylabel_post_insert()
#30 [internal function]: _drupal_shutdown_function()
#31 {main}Shutdown hook I suspect is the culprit:
/**
* Re-save the entity to trigger creation of the automatic label if necessary.
*/
function _auto_entitylabel_post_insert(EntityInterface $entityArg) {
if ($entityArg instanceof ContentEntityInterface) {
// Because of the way PHP shutdown functions work this operation may
// be called during an entity delete operation (as demonstrated by
// the Kernel test). Reload the entity from the database to check that
// it hasn't been deleted.
if ($entity = \Drupal::entityTypeManager()->getStorage($entityArg->getEntityTypeId())->loadUnchanged($entityArg->id())) {
// The entity hasn't been deleted, continue processing.
// Again because of the way shutdown functions work this
// function may be called for entities that don't have an
// autolabel or ones that do but don't need to be saved
// again. Run the same checks that were run during the
// insert hook to be sure that this entity really needs the
// second save.
$decorator = \Drupal::service('auto_entitylabel.entity_decorator');
/** @var \Drupal\auto_entitylabel\AutoEntityLabelManager $decorated_entity */
$decorated_entity = $decorator->decorate($entity);
if ($decorated_entity->hasLabel()
&& $decorated_entity->autoLabelNeeded()
&& $decorated_entity->getNewContentBehavior() === AutoEntityLabelManager::AFTER_SAVE) {
if ($entity->getEntityType()->isRevisionable()) {
$entity->setNewRevision(FALSE);
}
$entity->save();
}
}
}
}
Issue fork auto_entitylabel-3592471
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
abenbow