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

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

motame created an issue. See original summary.

motame’s picture

Assigned: Unassigned » motame
motame’s picture

Status: Active » Needs review
ericvl’s picture

@motame
Thank you to confirm my remark from 2 years ago :-)
It was correct then and is still correct now.
I"m using this module with this modification in a local patch since then.

motame’s picture

@ericvl, you are welcome !
The fix is absolutely right.

kolin’s picture

Status: Needs review » Reviewed & tested by the community

I created an MR for the existing issue branch so it can be applied via composer-patches.

I've tested the change and it works as expected.