FileEntityNormalizer::denormalize(): Return value must be of type ArrayObject|array|string|int|float|bool|null

Created on 11 November 2024, about 1 month ago

Problem/Motivation

While the content sync export is working properly, the import fails when importing the files (the entity type file).
The returned error is :
[error] TypeError: Drupal\content_sync\Normalizer\FileEntityNormalizer::denormalize(): Return value must be of type ArrayObject|array|string|int|float|bool|null, Drupal\file\Entity\File returned in Drupal\content_sync\Normalizer\FileEntityNormalizer->denormalize() (line 141 of /home/meharga/eclipse-workspaces/mmoda-staging/mmoda-st3/web/modules/contrib/content_sync/src/Normalizer/FileEntityNormalizer.php) #0 /home/meharga/eclipse-workspaces/mmoda-staging/mmoda-st3/vendor/symfony/serializer/Serializer.php(247): Drupal\content_sync\Normalizer\FileEntityNormalizer->denormalize()

Steps to reproduce

  • Create a fresh instance of Drupal 10 (in my case 10.3.2)
  • Install, enable and configure the module content synchronisation
  • Create an article within an image inside (to have a file to export/import)
  • Export the full content with "drush cse -y" (it goes smoothly)
  • Import the same content with "drush csi -y" and the error raises ...

Proposed resolution

The method Drupal\content_sync\Normalizer\FileEntityNormalizer->denormalize() is calling Drupal\content_sync\Normalizer\ContentEntityNormalizer->denormalize() which is calling Drupal\serialization\Normalizer\EntityNormalizer->denormalize().
The latter is returning an object while the first one is not expected to return that, an object. It is returning : array|string|int|float|bool|\ArrayObject|NULL
public function denormalize($data, $class, $format = NULL, array $serializer_context = array()): array|string|int|float|bool|\ArrayObject|NULL {

This should be replaced by :
public function denormalize($data, $class, $format = NULL, array $serializer_context = array()): mixed {

As it is the case of the first two methods :

  • Drupal\content_sync\Normalizer\FileEntityNormalizer->denormalize()
  • Drupal\content_sync\Normalizer\ContentEntityNormalizer->denormalize()

This is already suggested in the issue : Drupal 10 compatibility update 📌 Drupal 10 compatibility update RTBC

🐛 Bug report
Status

Active

Version

4.0

Component

Import

Created by

🇨🇭Switzerland motame

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

Comments & Activities

Production build 0.71.5 2024