Warning: Undefined array key "anonymous" in AiAssistantApiRunner->userHasAccess()

Created on 2 February 2025, 20 days ago

Problem/Motivation

Facing the following warning with the login page.
In the case of using the admin theme for anonymous users.

Error message
Warning: Undefined array key "anonymous" in Drupal\ai_assistant_api\AiAssistantApiRunner->userHasAccess() (line 389 of modules/contrib/ai/modules/ai_assistant_api/src/AiAssistantApiRunner.php).
Drupal\ai_assistant_api\AiAssistantApiRunner->userHasAccess() (Line: 242)
Drupal\ai_chatbot\Plugin\Block\ChatFormBlock->build() (Line: 171)
Drupal\block\BlockViewBuilder::preRender()
call_user_func_array() (Line: 113)
Drupal\Core\Render\Renderer->doTrustedCallback() (Line: 870)
Drupal\Core\Render\Renderer->doCallback() (Line: 432)
Drupal\Core\Render\Renderer->doRender() (Line: 248)
Drupal\Core\Render\Renderer->render() (Line: 165)
Drupal\Core\Render\Renderer->Drupal\Core\Render\{closure}() (Line: 638)
Drupal\Core\Render\Renderer->executeInRenderContext() (Line: 164)
Drupal\Core\Render\Renderer->renderInIsolation() (Line: 191)
Drupal\Core\Render\Renderer->doRenderPlaceholder() (Line: 723)
Drupal\Core\Render\Renderer->Drupal\Core\Render\{closure}()
Fiber->start() (Line: 731)
Drupal\Core\Render\Renderer->replacePlaceholders() (Line: 608)
Drupal\Core\Render\Renderer->doRender() (Line: 248)
Drupal\Core\Render\Renderer->render() (Line: 153)
Drupal\Core\Render\Renderer->Drupal\Core\Render\{closure}() (Line: 638)
Drupal\Core\Render\Renderer->executeInRenderContext() (Line: 152)
Drupal\Core\Render\Renderer->renderRoot() (Line: 288)
Drupal\Core\Render\HtmlResponseAttachmentsProcessor->renderPlaceholders() (Line: 74)
Drupal\big_pipe\Render\BigPipeResponseAttachmentsProcessor->processAttachments() (Line: 45)
Drupal\Core\EventSubscriber\HtmlResponseSubscriber->onRespond()
call_user_func() (Line: 111)
Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher->dispatch() (Line: 214)
Symfony\Component\HttpKernel\HttpKernel->filterResponse() (Line: 202)
Symfony\Component\HttpKernel\HttpKernel->handleRaw() (Line: 76)
Symfony\Component\HttpKernel\HttpKernel->handle() (Line: 54)
Drupal\simple_oauth\HttpMiddleware\BasicAuthSwap->handle() (Line: 53)
Drupal\Core\StackMiddleware\Session->handle() (Line: 48)
Drupal\Core\StackMiddleware\KernelPreHandle->handle() (Line: 28)
Drupal\Core\StackMiddleware\ContentLength->handle() (Line: 32)
Drupal\big_pipe\StackMiddleware\ContentLength->handle() (Line: 201)
Drupal\page_cache\StackMiddleware\PageCache->fetch() (Line: 138)
Drupal\page_cache\StackMiddleware\PageCache->lookup() (Line: 87)
Drupal\page_cache\StackMiddleware\PageCache->handle() (Line: 48)
Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle() (Line: 51)
Drupal\Core\StackMiddleware\NegotiationMiddleware->handle() (Line: 36)
Drupal\Core\StackMiddleware\AjaxPageState->handle() (Line: 51)
Drupal\Core\StackMiddleware\StackedHttpKernel->handle() (Line: 741)
Drupal\Core\DrupalKernel->handle() (Line: 19)

Steps to reproduce

Given that a Drupal site has the AI, AI Agents, AI Assistance API modules were enabled
And the Gin Admin theme and Gin Login were configured for as the default for admins
And a DeepChat block was configured with an an assistance
And It was placed in the Gin admin theme block layouts
But no roles was selected for "When the user has the following roles"
When navigating to "/user/login"
Then the following warning will show
Warning: Undefined array key "anonymous" in AiAssistantApiRunner->userHasAccess()

It feels that Drupal will allow to render the block
then AI Assistant will check for user Has Access

Proposed resolution

Switch to only chosen roles
Add a warning to AI DeepChat block type to select user roles. "When the user has the following roles"
Not to leave it empty

Remaining tasks

User interface changes

API changes

Data model changes

🐛 Bug report
Status

Active

Version

1.0

Component

AI Assistants API

Created by

🇯🇴Jordan Rajab Natshah Jordan

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

Production build 0.71.5 2024