AiSearchBlockController fails with "Cannot load the 'block' entity with NULL ID" when directly accessing endpoint

Created on 25 March 2025, 18 days ago

Problem/Motivation

When directly accessing the /ai-search-block/query endpoint without proper parameters, the controller attempts to load a block entity with a NULL ID, resulting in an AssertionError. The controller doesn't properly validate the presence of required parameters before attempting to load the block entity.

Steps to reproduce

  1. Install the ai_search_block module on Drupal 10
  2. Directly navigate to /ai-search-block/query in the browser without any query parameters
  3. Observe the error: "AssertionError: Cannot load the "block" entity with NULL ID. in assert() (line 261 of core/lib/Drupal/Core/Entity/EntityStorageBase.php)"

Proposed resolution

Add proper validation for required parameters before attempting to load the block entity. The controller should check if $block_id is empty and return an appropriate error response instead of trying to load a block with a NULL ID.

Remaining tasks

  1. Implement the proposed fix
  2. Add tests to verify the controller properly handles missing parameters
  3. Review and commit the changes

User interface changes

None. This is a backend API endpoint fix.

API changes

The API will now return a proper error response with a 400 status code when required parameters are missing, instead of throwing an exception.

Data model changes

None.

🐛 Bug report
Status

Active

Version

1.0

Component

Code

Created by

🇵🇱Poland jorgik

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