Problem/Motivation We have a view that uses Search_API SOLR with content that uses the flag field, when it is indexed on save an error is triggered.
``` RuntimeException while trying to render item entity:node/19:en with view mode full for search index default: Failed to start the session because headers have already been sent by "/var/www/html/vendor/symfony/http-foundation/Response.php" at line 384. in Symfony\Component\HttpFoundation\Session\Storage\NativeSessionStorage->start() (line 152 of /var/www/html/vendor/symfony/http-foundation/Session/Storage/NativeSessionStorage.php).
```
After debug it I saw that the hook flag_views_query_substitutions is triggered, and the code from FlagService::getAnonymousSessionId triggered the error.
$request->getSession()->get('flag.session_id')
Why is it necessary the query substitution for flag session? I saw that is used on the plugin https://git.drupalcode.org/project/flag/-/blob/8.x-4.x/src/Plugin/views/... but I do not understand if it is relevant.
``` $flag_roles = user_roles(FALSE, "flag " . $flag->id()); if (isset($flag_roles[RoleInterface::ANONYMOUS_ID]) && $this->currentUser->isAnonymous()) { // Disable page caching for anonymous users. $this->pageCacheKillSwitch->trigger();
// Add a condition to the join on the PHP session id for anonymous users.
$this->definition['extra'][] = [
'field' => 'session_id',
'value' => '***FLAG_CURRENT_USER_SID***',
];
}
``` Steps to reproduce * Create new content with a flag field. * Index it on a search_api view * The error will appear on the log
Proposed resolution Check that the session is already started on method FlagService::getAnonymousSessionId()
``` $session_id = $request->hasSession() && $request->getSession()->isStarted() ? $request->getSession()->get('flag.session_id') : NULL;
```