TypeError: Drupal\tmgmt_deepl\Plugin\tmgmt\Translator\DeeplTranslator::doRequest(): Return value must be of type array, null returned

Created on 1 August 2025, 13 days ago

Problem/Motivation

Submitting content entities of type Commerce Product to DeepL I get the following error and translation doesn't work:

TypeError: Drupal\tmgmt_deepl\Plugin\tmgmt\Translator\DeeplTranslator::doRequest(): Return value must be of type array, null returned in Drupal\tmgmt_deepl\Plugin\tmgmt\Translator\DeeplTranslator::doRequest() (Zeile 461 in/web/modules/contrib/tmgmt_deepl/src/Plugin/tmgmt/Translator/DeeplTranslator.php).

Backtrace:

#0 /web/modules/contrib/tmgmt_deepl/src/Plugin/tmgmt/Translator/DeeplTranslator.php(608): Drupal\tmgmt_deepl\Plugin\tmgmt\Translator\DeeplTranslator::doRequest()
#1 /web/core/includes/batch.inc(297): Drupal\tmgmt_deepl\Plugin\tmgmt\Translator\DeeplTranslator::batchRequestTranslation()
#2 /web/core/includes/batch.inc(139): _batch_process()
#3 /web/core/includes/batch.inc(95): _batch_do()
#4 /web/core/modules/system/src/Controller/BatchController.php(52): _batch_page()
#5 [internal function]: Drupal\system\Controller\BatchController->batchPage()
#6 /web/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(123): call_user_func_array()
#7 /web/core/lib/Drupal/Core/Render/Renderer.php(638): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}()
#8 /web/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(121): Drupal\Core\Render\Renderer->executeInRenderContext()
#9 /web/core/lib/Drupal/Core/EventSubscriber/EarlyRenderingControllerWrapperSubscriber.php(97): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext()
#10 /vendor/symfony/http-kernel/HttpKernel.php(181): Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}()
#11 /vendor/symfony/http-kernel/HttpKernel.php(76): Symfony\Component\HttpKernel\HttpKernel->handleRaw()
#12 /web/core/lib/Drupal/Core/StackMiddleware/Session.php(53): Symfony\Component\HttpKernel\HttpKernel->handle()
#13 /web/core/lib/Drupal/Core/StackMiddleware/KernelPreHandle.php(48): Drupal\Core\StackMiddleware\Session->handle()
#14 /web/core/lib/Drupal/Core/StackMiddleware/ContentLength.php(28): Drupal\Core\StackMiddleware\KernelPreHandle->handle()
#15 /web/core/modules/big_pipe/src/StackMiddleware/ContentLength.php(32): Drupal\Core\StackMiddleware\ContentLength->handle()
#16 /web/core/modules/page_cache/src/StackMiddleware/PageCache.php(116): Drupal\big_pipe\StackMiddleware\ContentLength->handle()
#17 /web/core/modules/page_cache/src/StackMiddleware/PageCache.php(90): Drupal\page_cache\StackMiddleware\PageCache->pass()
#18 /web/core/modules/ban/src/BanMiddleware.php(50): Drupal\page_cache\StackMiddleware\PageCache->handle()
#19 /web/core/lib/Drupal/Core/StackMiddleware/ReverseProxyMiddleware.php(48): Drupal\ban\BanMiddleware->handle()
#20 /web/core/lib/Drupal/Core/StackMiddleware/NegotiationMiddleware.php(51): Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle()
#21 /web/core/lib/Drupal/Core/StackMiddleware/AjaxPageState.php(36): Drupal\Core\StackMiddleware\NegotiationMiddleware->handle()
#22 /web/modules/contrib/remove_http_headers/src/StackMiddleware/RemoveHttpHeadersMiddleware.php(49): Drupal\Core\StackMiddleware\AjaxPageState->handle()
#23 /web/core/lib/Drupal/Core/StackMiddleware/StackedHttpKernel.php(51): Drupal\remove_http_headers\StackMiddleware\RemoveHttpHeadersMiddleware->handle()
#24 /web/core/lib/Drupal/Core/DrupalKernel.php(741): Drupal\Core\StackMiddleware\StackedHttpKernel->handle()
#25 /web/index.php(19): Drupal\Core\DrupalKernel->handle()
#26 {main}

Steps to reproduce

Select Commerce Product (Content Entities) and submit them to DeepL like regularly - this might be specific to the entities or entity types, so we should not focus on Commerce Product entities, but instead handle and fix the issue code-wise (expected type)

Proposed resolution

Find out why null is returned instead of an array and handle that case properly

Remaining tasks

User interface changes

API changes

Data model changes

🐛 Bug report
Status

Active

Version

2.3

Component

Code

Created by

🇩🇪Germany Anybody Porta Westfalica

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

Merge Requests

Comments & Activities

  • Issue created by @Anybody
  • 🇩🇪Germany Anybody Porta Westfalica

    anybody changed the visibility of the branch 3539226-typeerror-drupaltmgmtdeeplplugintmgmttranslatordeepltranslatordorequest-return to hidden.

  • 🇩🇪Germany Anybody Porta Westfalica

    Ah sorry, just saw that we were using 2.2.12. In 2.3.x this code doesn't exist any more. I may not upgrade to 2.3.0-alpha to test it, so let's postpone this for now. If the maintainer knows if these lines of code might still be affected in 2.3.x, we can set this active again.

    These are the affected lines:

    // Process the JSON result into array.
        if (isset($response) && $response instanceof ResponseInterface) {
          /** @var array $return */
          $return = json_decode($response->getBody(), TRUE);
          return $return;
        }
    

    Which means that propably json_decode() of the response is NULL, but an array is expected, so we should maybe transform NULL's to []?

  • Pipeline finished with Success
    13 days ago
    Total: 306s
    #562183
  • 🇩🇪Germany Anybody Porta Westfalica

    Okay looks like DeepL returns an empty string here ($response->getBody()), in cases where this happens.

  • Pipeline finished with Success
    13 days ago
    Total: 182s
    #562186
Production build 0.71.5 2024