CacheContextsManager.php must be of type string, array given in str_contains

Created on 4 April 2024, 8 months ago
Updated 18 April 2024, 7 months ago

After updating 1.6 to 2.2.2 and updb, I'm facing this problem. I couldn't find who added that context as an array.

TypeError: str_contains(): Argument #1 ($haystack) must be of type string, array given in str_contains() (line 181 of core/lib/Drupal/Core/Cache/Context/CacheContextsManager.php).

Drupal\Core\Cache\Context\CacheContextsManager->optimizeTokens(Array) (Line: 156)
Drupal\Core\EventSubscriber\FinishResponseSubscriber->onRespond(Object, 'kernel.response', Object)
call_user_func(Array, Object, 'kernel.response', Object) (Line: 111)
Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher->dispatch(Object, 'kernel.response') (Line: 214)
Symfony\Component\HttpKernel\HttpKernel->filterResponse(Object, Object, 1) (Line: 202)

🐛 Bug report
Status

Closed: works as designed

Version

2.2

Component

Code

Created by

🇹🇷Turkey emircan erkul Turkey

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

Comments & Activities

  • Issue created by @emircan erkul
  • Assigned to abhishek_virasat
  • Issue was unassigned.
  • 🇹🇷Turkey emircan erkul Turkey

    Update: might not be related, after removing settings.local.php this error disappears. In my environment, there are problems with NullBackendFactory

  • Status changed to Closed: works as designed 7 months ago
  • 🇹🇷Turkey emircan erkul Turkey

    Find out one of our custom modules causing this problem. Tracing that one was extremely difficult maybe impossible, found by checking and disabling things manually.

    - $build['#cache']['contexts'][] = ['url', 'user'];
    - $build['#cache']['tags'][] = ['user:' . $current_uid, 'group_content_list'];
    + $build['#cache']['contexts'] = array_merge($build['#cache']['contexts'], ['url', 'user']);
    + $build['#cache']['tags'] = array_merge($build['#cache']['tags'], ['user:' . $current_uid, 'group_content_list']);

Production build 0.71.5 2024