Adding custom_value to index breaks endpoint

Created on 27 June 2024, 5 months ago
Updated 23 July 2024, 4 months ago

Problem/Motivation

I have a database search index that I have been using with the Search API Decoupled module for quite a while. It works without any issue. I am working on a website using Drupal 10.2.7. Today, I attempted to add a new field to my search index using the custom_value property path. As soon as I save the index configuration with the new field, the search api endpoint for this index breaks with the following error:

LogicException: The controller result claims to be providing relevant cache metadata, but leaked metadata was detected. Ensure you are not rendering content too early. Returned object class: Drupal\Core\Cache\CacheableJsonResponse. in Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext() (line 154 of core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php).

Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 181)
Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object, 1) (Line: 76)
Symfony\Component\HttpKernel\HttpKernel->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: 28)
Drupal\Core\StackMiddleware\ContentLength->handle(Object, 1, 1) (Line: 32)
Drupal\big_pipe\StackMiddleware\ContentLength->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: 48)
Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object, 1, 1) (Line: 51)
Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object, 1, 1) (Line: 36)
Drupal\Core\StackMiddleware\AjaxPageState->handle(Object, 1, 1) (Line: 51)
Drupal\Core\StackMiddleware\StackedHttpKernel->handle(Object, 1, 1) (Line: 704)
Drupal\Core\DrupalKernel->handle(Object) (Line: 19)

The custom value for this field is a token: [node:field_publication_date:date:html_year]

The field type doesn't seem to matter. I've tried integer, string, and date. The endpoint is still broken. Removing the field eliminates the error.

I tried adding the field, reindexing, and then adding the field to a search index view. The content of the field was as expected. I cannot tell why adding this type of field to the index would break the endpoint. Perhaps I cannot use a token? If I set the value of the field to be some string (like '2024'), the error is eliminated.

If tokens are just not allowed, this should probably be documented.

πŸ› Bug report
Status

Fixed

Version

1.0

Component

Endpoint

Created by

πŸ‡ΊπŸ‡ΈUnited States aaronpinero

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

Comments & Activities

  • Issue created by @aaronpinero
  • πŸ‡©πŸ‡ͺGermany a.dmitriiev

    Actually I was never using tokens inside the indexed field before, so thank you for the report. I will try to check what is the problem here with token.

  • πŸ‡©πŸ‡ͺGermany a.dmitriiev

    I have tried the custom value field for the search index, I also tried the date field as in your example, and it works without problems for me. Maybe because I use Drupal 10.3.0, Search API 8.x-1.35 and 1.x-dev version of Search API Decoupled. The token I used is [node:news_date:date:html_year]

  • πŸ‡©πŸ‡ͺGermany a.dmitriiev

    Please give more information about your setup, like version of Search API. I have realized right now, that token is not actually used when the result is displayed, the token is used on index time. So Search API extracts the value from your token when the content is being indexed, and then when the search results are being displayed, there is no transformation of token anymore, because in search index the value for this token is already stored, not the token itself.

  • πŸ‡ΊπŸ‡ΈUnited States aaronpinero

    I upgraded my instance to Drupal 10.3.1 and PHP 8.3 and the problem I was seeing went away. I guess whatever it was is fixed in the latest version of Drupal.

  • Status changed to Fixed 5 months ago
  • πŸ‡©πŸ‡ͺGermany a.dmitriiev

    Good to hear, that it is now working for you. Though it is still interesting what was wrong in 10.2.7 about it.

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

Production build 0.71.5 2024