AI Chatbot: PHP Error: Null check needed in AiAssistantApiRunner::setAssistant() when no default provider is configured
>>> [!note] Migrated issue <!-- Drupal.org comment --> <!-- Migrated from issue #3512736. --> Reported by: [anjaliprasannan](https://www.drupal.org/user/3637917) Related to !508 >>> <h3 id="summary-problem-motivation">Problem/Motivation</h3> <p>Php error for null check found when no ai provider is enabled in AI chatbot block.</p> <pre>The website encountered an unexpected error. Try again later.<br>TypeError: Drupal\ai_assistant_api\AiAssistantApiRunner::setAssistant(): Argument #1 ($assistant) must be of type Drupal\ai_assistant_api\Entity\AiAssistant, null given, called in /var/www/html/modules/contrib/ai/modules/ai_chatbot/src/Plugin/Block/ChatFormBlock.php on line 240 in Drupal\ai_assistant_api\AiAssistantApiRunner-&gt;setAssistant() (line 164 of modules/contrib/ai/modules/ai_assistant_api/src/AiAssistantApiRunner.php).<br>Drupal\ai_assistant_api\AiAssistantApiRunner-&gt;setAssistant() (Line: 240)<br>Drupal\ai_chatbot\Plugin\Block\ChatFormBlock-&gt;build() (Line: 175)<br>Drupal\block\BlockViewBuilder::preRender()<br>call_user_func_array() (Line: 107)<br>Drupal\Core\Render\Renderer-&gt;doTrustedCallback() (Line: 830)<br>Drupal\Core\Render\Renderer-&gt;doCallback() (Line: 387)<br>Drupal\Core\Render\Renderer-&gt;doRender() (Line: 203)<br>Drupal\Core\Render\Renderer-&gt;render() (Line: 120)<br>Drupal\Core\Render\Renderer-&gt;Drupal\Core\Render\{closure}() (Line: 593)<br>Drupal\Core\Render\Renderer-&gt;executeInRenderContext() (Line: 119)<br>Drupal\Core\Render\Renderer-&gt;renderInIsolation() (Line: 146)<br>Drupal\Core\Render\Renderer-&gt;doRenderPlaceholder() (Line: 183)<br>Drupal\Core\Render\Renderer-&gt;renderPlaceholder() (Line: 715)<br>Drupal\big_pipe\Render\BigPipe-&gt;renderPlaceholder() (Line: 495)<br>Drupal\big_pipe\Render\BigPipe-&gt;Drupal\big_pipe\Render\{closure}()<br>Fiber-&gt;start() (Line: 502)<br>Drupal\big_pipe\Render\BigPipe-&gt;sendPlaceholders() (Line: 254)<br>Drupal\big_pipe\Render\BigPipe-&gt;sendContent() (Line: 116)<br>Drupal\big_pipe\Render\BigPipeResponse-&gt;sendContent() (Line: 395)<br>Symfony\Component\HttpFoundation\Response-&gt;send() (Line: 20)</pre><h4 id="summary-steps-reproduce">Steps to reproduce</h4> <p>- Install the AI module and enable the AI Chatbot submodule<br> - Do not configure any AI provider<br> - Place the ai chatbot block in sidebar(any) region and visit the home page to view the chatbot</p> <p>At the bottom of the page the php error shows up.</p> <h3 id="summary-proposed-resolution">Proposed resolution</h3> <h3 id="summary-remaining-tasks">Remaining tasks</h3> <h3 id="summary-ui-changes">User interface changes</h3> <h3 id="summary-api-changes">API changes</h3> <h3 id="summary-data-model-changes">Data model changes</h3>
issue