Problem/Motivation

Our groupNotifyIsMuted checks all flags for the current user, however, for AN the flag service requires a session id as per:
https://git.drupalcode.org/project/flag/-/commit/497e170c267780dc314e0f0...

If not provided, it will trigger the Exception.

Proposed resolution

In our case we can use the same $this->flagService->getAnonymousSessionId to make sure it returns NULL if the user is logged in or provide a/the session ID for AN.

The services definition is changed, make sure you update the container cache using the deployment identifier.

Comments

ronaldtebrake created an issue. See original summary.

ronaldtebrake’s picture

socialnicheguru’s picture

Status: Needs review » Needs work

The patch caused major error when i tested it.
I clicked on a checkbox added to the user from from another module, entity_legal.
I was an authenticated user without andy other roles.
php8.1
Drupal 9.5.8

"LogicException: An anonymous user must be identified by session ID - https://www.drupal.org/project/social/issues/3355315":"https://patch-diff.githubusercontent.com/raw/goalgorilla/open_social/pul...",

The website encountered an unexpected error. Please try again later.
ArgumentCountError: Too few arguments to function Drupal\social_group\GroupMuteNotify::__construct(), 1 passed in social-11.9.x/html/core/lib/Drupal/Component/DependencyInjection/Container.php on line 259 and exactly 2 expected in Drupal\social_group\GroupMuteNotify->__construct() (line 47 of profiles/contrib/social/modules/social_features/social_group/src/GroupMuteNotify.php).
Drupal\social_group\GroupMuteNotify->__construct(Object) (Line: 259)

Drupal\Component\DependencyInjection\Container->createService(Array, 'social_group.group_mute_notify') (Line: 177)
Drupal\Component\DependencyInjection\Container->get('social_group.group_mute_notify') (Line: 74)
Drupal\activity_basics\Plugin\ActivityContext\OwnerActivityContext::create(Object, Array, 'owner_activity_context', Array) (Line: 21)
Drupal\Core\Plugin\Factory\ContainerFactory->createInstance('owner_activity_context', Array) (Line: 83)
Drupal\Component\Plugin\PluginManagerBase->createInstance('owner_activity_context') (Line: 188)
Drupal\activity_logger\Service\ActivityLoggerFactory->getMessageTypes('create_entitiy_action', Object) (Line: 84)
Drupal\activity_logger\Service\ActivityLoggerFactory->createMessages(Object, 'create_entitiy_action') (Line: 31)
Drupal\activity_creator\Plugin\ActivityActionBase->createMessage(Object) (Line: 33)
Drupal\activity_basics\Plugin\ActivityAction\CreateActivityAction->create(Object) (Line: 82)
_activity_basics_entity_action(Object, 'create_entitiy_action') (Line: 18)
activity_basics_entity_insert(Object)
call_user_func_array(Object, Array) (Line: 426)
Drupal\Core\Extension\ModuleHandler->Drupal\Core\Extension\{closure}(Object, 'activity_basics') (Line: 405)
Drupal\Core\Extension\ModuleHandler->invokeAllWith('entity_insert', Object) (Line: 433)
Drupal\Core\Extension\ModuleHandler->invokeAll('entity_insert', Array) (Line: 251)
Drupal\Core\Entity\EntityStorageBase->invokeHook('insert', Object) (Line: 903)
Drupal\Core\Entity\ContentEntityStorageBase->invokeHook('insert', Object) (Line: 598)
Drupal\Core\Entity\EntityStorageBase->doPostSave(Object, ) (Line: 784)
Drupal\Core\Entity\ContentEntityStorageBase->doPostSave(Object, ) (Line: 523)
Drupal\Core\Entity\EntityStorageBase->save(Object) (Line: 804)
Drupal\Core\Entity\Sql\SqlContentEntityStorage->save(Object) (Line: 339)
Drupal\Core\Entity\EntityBase->save() (Line: 98)
Drupal\entity_legal\Form\EntityLegalDocumentAcceptanceForm->submitForm(Array, Object)
call_user_func_array(Array, Array) (Line: 114)
Drupal\Core\Form\FormSubmitter->executeSubmitHandlers(Array, Object) (Line: 52)
Drupal\Core\Form\FormSubmitter->doSubmitForm(Array, Object) (Line: 595)
Drupal\Core\Form\FormBuilder->processForm('entity_legal_document_acceptance_form', Array, Object) (Line: 323)
Drupal\Core\Form\FormBuilder->buildForm(Object, Object) (Line: 222)
Drupal\Core\Form\FormBuilder->getForm(Object) (Line: 130)
Drupal\entity_legal\Entity\EntityLegalDocument->getAcceptanceForm() (Line: 27)
Drupal\entity_legal\EntityLegalDocumentVersionViewBuilder->buildComponents(Array, Array, Array, 'full') (Line: 282)
Drupal\Core\Entity\EntityViewBuilder->buildMultiple(Array) (Line: 239)
Drupal\Core\Entity\EntityViewBuilder->build(Array)
call_user_func_array(Array, Array) (Line: 101)
Drupal\Core\Render\Renderer->doTrustedCallback(Array, Array, 'Render #pre_render callbacks must be methods of a class that implements \Drupal\Core\Security\TrustedCallbackInterface or be an anonymous function. The callback was %s. See https://www.drupal.org/node/2966725', 'exception', 'Drupal\Core\Render\Element\RenderCallbackInterface') (Line: 788)
Drupal\Core\Render\Renderer->doCallback('#pre_render', Array, Array) (Line: 374)
Drupal\Core\Render\Renderer->doRender(Array, ) (Line: 204)
Drupal\Core\Render\Renderer->render(Array, ) (Line: 242)
Drupal\Core\Render\MainContent\HtmlRenderer->Drupal\Core\Render\MainContent\{closure}() (Line: 580)
Drupal\Core\Render\Renderer->executeInRenderContext(Object, Object) (Line: 243)
Drupal\Core\Render\MainContent\HtmlRenderer->prepare(Array, Object, Object) (Line: 132)
Drupal\Core\Render\MainContent\HtmlRenderer->renderResponse(Array, Object, Object) (Line: 90)
Drupal\Core\EventSubscriber\MainContentViewSubscriber->onViewRenderArray(Object, 'kernel.view', Object)
call_user_func(Array, Object, 'kernel.view', Object) (Line: 142)
Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher->dispatch(Object, 'kernel.view') (Line: 174)
Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object, 1) (Line: 81)
Symfony\Component\HttpKernel\HttpKernel->handle(Object, 1, 1) (Line: 54)
Drupal\simple_oauth\HttpMiddleware\BasicAuthSwap->handle(Object, 1, 1) (Line: 58)
Drupal\Core\StackMiddleware\Session->handle(Object, 1, 1) (Line: 48)
Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object, 1, 1) (Line: 106)
Drupal\page_cache\StackMiddleware\PageCache->pass(Object, 1, 1) (Line: 85)
Drupal\page_cache\StackMiddleware\PageCache->handle(Object, 1, 1) (Line: 43)
Drupal\webform_product\RedirectMiddleware->handle(Object, 1, 1) (Line: 48)
Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object, 1, 1) (Line: 51)
Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object, 1, 1) (Line: 23)
Stack\StackedHttpKernel->handle(Object, 1, 1) (Line: 728)
Drupal\Core\DrupalKernel->handle(Object) (Line: 19)

ronaldtebrake’s picture

Issue summary: View changes

Thanks for the input.

Did you update/use the deployment identifier to indicate there are changes to the services definition or clear the container cache in any way?
A drush cr seemed to do the trick for me to ensure the below changes are taking in to account.

social_group.group_mute_notify:
     class: Drupal\social_group\GroupMuteNotify
-    arguments:
-      - '@flag'
+    arguments: ['@flag', '@entity_type.manager']

The patch you're using indicates correctly that there are two arguments by the looks of it.

socialnicheguru’s picture

You were right @ronaldtebrake.

I had to manually clear caches for some reason.

socialnicheguru’s picture

Status: Needs work » Reviewed & tested by the community
ronaldtebrake’s picture

Thanks for letting me know @SocialNicheGuru, appreciated!

ronaldtebrake’s picture

Status: Reviewed & tested by the community » Fixed
tbsiqueira’s picture

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.