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;
Issue fork flag-3323151
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 #3
eduardo morales albertiComment #4
eduardo morales albertiThe hook also is executed on views that do not have flag. Should be changed the conditions to only execute if the view has the flag field or the FlagViewsRelationship?
https://git.drupalcode.org/project/flag/-/blob/8.x-4.x/flag.views_execut...
Comment #6
daniel korte@Eduardo Morales Alberti I think so. That is the issue I am having. I added a check to the merge request. Please review, thanks.
Comment #7
hitchshockRTBC from my side.
It also fixes the search-API error when I try to index a rendered field where the view mode uses a flag field.
Comment #8
eduardo morales albertiAny news?
Comment #9
abarrioIt fixes my problem too. I think is RTBC too.
Comment #12
berdirMerged.
Comment #13
berdir