Error when translating: insertTextMetadata(): Argument #2 ($metadata) must be of type array, null given

Created on 22 April 2025, 16 days ago

Problem/Motivation

Translating content using chatgpt-4o-mini does not work. Probably other models too.

Steps to reproduce

  • Make sure you have a multilanguage site and a layoutbuilder content type
  • Enable the ai, ai_translate and ai_provider_openai modules
  • I created a new (free) openai account and created an API key at https://platform.openai.com
  • Go to /admin/config/system/keys/add and add the api key
  • Go to /admin/config/ai/providers to set up the OpenAi provider
  • Go to /admin/config/ai/settings to set up the translation: 'Default Provider': 'Chat proxy to LLM'. 'Default Model': 'gpt-4o-mini'
  • Create a page full of layoutbuilder blocks in your default language
  • Click on translate
  • Click on 'Translate with gpt-4o-mini'
  • You see a progress bar translating the page and all blocks

At the end I get this error:

Er is een AJAX HTTP fout opgetreden.
HTTP-resultaatcode: 500
Debug informatie volgt.
Pad: /nl/batch?id=291&op=do_nojs&op=do
Statustekst: error
Antwoordtekst: {"error":{"type":"TypeError","message":"Drupal\\ai_translate\\TextExtractor::insertTextMetadata(): Argument #2 ($metadata) must be of type array, null given, called in \/var\/www\/html\/web\/modules\/contrib\/ai\/modules\/ai_translate\/src\/Controller\/AiTranslateController.php on line 182","code":0,"file":"\/var\/www\/html\/web\/modules\/contrib\/ai\/modules\/ai_translate\/src\/TextExtractor.php","line":80,"trace":[{"file":"\/var\/www\/html\/web\/modules\/contrib\/ai\/modules\/ai_translate\/src\/TextExtractor.php","line":80,"function":null,"class":"TypeError","args":["Drupal\\ai_translate\\TextExtractor::insertTextMetadata(): Argument #2 ($metadata) must be of type array, null given, called in \/var\/www\/html\/web\/modules\/contrib\/ai\/modules\/ai_translate\/src\/Controller\/AiTranslateController.php on line 182"]},{"file":"\/var\/www\/html\/web\/modules\/contrib\/ai\/modules\/ai_translate\/src\/Controller\/AiTranslateController.php","line":182,"function":"insertTextMetadata","class":"Drupal\\ai_translate\\TextExtractor","args":[]},{"file":"\/var\/www\/html\/web\/core\/includes\/batch.inc","line":297,"function":"insertTranslation","class":"Drupal\\ai_translate\\Controller\\AiTranslateController","args":[]},{"file":"\/var\/www\/html\/web\/core\/includes\/batch.inc","line":139,"function":"_batch_process","class":null,"args":[]},{"file":"\/var\/www\/html\/web\/core\/includes\/batch.inc","line":95,"function":"_batch_do","class":null,"args":[]},{"file":"\/var\/www\/html\/web\/core\/modules\/system\/src\/Controller\/BatchController.php","line":52,"function":"_batch_page","class":null,"args":[]},{"file":"\/var\/www\/html\/web\/core\/lib\/Drupal\/Core\/EventSubscriber\/EarlyRenderingControllerWrapperSubscriber.php","line":123,"function":"batchPage","class":"Drupal\\system\\Controller\\BatchController","args":[]},{"file":"\/var\/www\/html\/web\/core\/lib\/Drupal\/Core\/EventSubscriber\/EarlyRenderingControllerWrapperSubscriber.php","line":123,"function":"call_user_func_array","class":null,"args":[]},{"file":"\/var\/www\/html\/web\/core\/lib\/Drupal\/Core\/Render\/Renderer.php","line":593,"function":"Drupal\\Core\\EventSubscriber\\{closure}","class":"Drupal\\Core\\EventSubscriber\\EarlyRenderingControllerWrapperSubscriber","args":[]},{"file":"\/var\/www\/html\/web\/core\/lib\/Drupal\/Core\/EventSubscriber\/EarlyRenderingControllerWrapperSubscriber.php","line":121,"function":"executeInRenderContext","class":"Drupal\\Core\\Render\\Renderer","args":[]},{"file":"\/var\/www\/html\/web\/core\/lib\/Drupal\/Core\/EventSubscriber\/EarlyRenderingControllerWrapperSubscriber.php","line":97,"function":"wrapControllerExecutionInRenderContext","class":"Drupal\\Core\\EventSubscriber\\EarlyRenderingControllerWrapperSubscriber","args":[]},{"file":"\/var\/www\/html\/vendor\/symfony\/http-kernel\/HttpKernel.php","line":183,"function":"Drupal\\Core\\EventSubscriber\\{closure}","class":"Drupal\\Core\\EventSubscriber\\EarlyRenderingControllerWrapperSubscriber","args":[]},{"file":"\/var\/www\/html\/vendor\/symfony\/http-kernel\/HttpKernel.php","line":76,"function":"handleRaw","class":"Symfony\\Component\\HttpKernel\\HttpKernel","args":[]},{"file":"\/var\/www\/html\/web\/core\/lib\/Drupal\/Core\/StackMiddleware\/Session.php","line":53,"function":"handle","class":"Symfony\\Component\\HttpKernel\\HttpKernel","args":[]},{"file":"\/var\/www\/html\/web\/core\/lib\/Drupal\/Core\/StackMiddleware\/KernelPreHandle.php","line":48,"function":"handle","class":"Drupal\\Core\\StackMiddleware\\Session","args":[]},{"file":"\/var\/www\/html\/web\/core\/lib\/Drupal\/Core\/StackMiddleware\/ContentLength.php","line":28,"function":"handle","class":"Drupal\\Core\\StackMiddleware\\KernelPreHandle","args":[]},{"file":"\/var\/www\/html\/web\/core\/modules\/page_cache\/src\/StackMiddleware\/PageCache.php","line":116,"function":"handle","class":"Drupal\\Core\\StackMiddleware\\ContentLength","args":[]},{"file":"\/var\/www\/html\/web\/core\/modules\/page_cache\/src\/StackMiddleware\/PageCache.php","line":90,"function":"pass","class":"Drupal\\page_cache\\StackMiddleware\\PageCache","args":[]},{"file":"\/var\/www\/html\/web\/core\/lib\/Drupal\/Core\/StackMiddleware\/ReverseProxyMiddleware.php","line":48,"function":"handle","class":"Drupal\\page_cache\\StackMiddleware\\PageCache","args":[]},{"file":"\/var\/www\/html\/web\/core\/lib\/Drupal\/Core\/StackMiddleware\/NegotiationMiddleware.php","line":51,"function":"handle","class":"Drupal\\Core\\StackMiddleware\\ReverseProxyMiddleware","args":[]},{"file":"\/var\/www\/html\/web\/core\/lib\/Drupal\/Core\/StackMiddleware\/AjaxPageState.php","line":36,"function":"handle","class":"Drupal\\Core\\StackMiddleware\\NegotiationMiddleware","args":[]},{"file":"\/var\/www\/html\/web\/modules\/contrib\/whoops\/src\/StackMiddleware\/WhoopsMiddleware.php","line":49,"function":"handle","class":"Drupal\\Core\\StackMiddleware\\AjaxPageState","args":[]},{"file":"\/var\/www\/html\/web\/core\/lib\/Drupal\/Core\/StackMiddleware\/StackedHttpKernel.php","line":51,"function":"handle","class":"Drupal\\whoops\\StackMiddleware\\WhoopsMiddleware","args":[]},{"file":"\/var\/www\/html\/web\/core\/lib\/Drupal\/Core\/DrupalKernel.php","line":709,"function":"handle","class":"Drupal\\Core\\StackMiddleware\\StackedHttpKernel","args":[]},{"file":"\/var\/www\/html\/web\/index.php","line":19,"function":"handle","class":"Drupal\\Core\\DrupalKernel","args

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

🐛 Bug report
Status

Active

Component

Code

Created by

🇧🇪Belgium flyke

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

Comments & Activities

Production build 0.71.5 2024