Argument #3 ($serializer) must be of type Drupal\Component\Serialization\ObjectAwareSerializationInterface

Created on 1 January 2025, 3 months ago

Problem/Motivation

After update to Drupal 9.5 I get this error:

Fatal error: Uncaught TypeError: Drupal\tome_static\StaticCache::__construct(): Argument #3 ($serializer) must be of type Drupal\Component\Serialization\ObjectAwareSerializationInterface, Drupal\Component\Serialization\PhpSerialize given, called in /var/www/html/web/core/lib/Drupal/Component/DependencyInjection/Container.php on line 259 and defined in /var/www/html/web/modules/contrib/tome/modules/tome_static/src/StaticCache.php:35

Steps to reproduce

When I run drush cr

πŸ› Bug report
Status

Active

Version

1.13

Component

Code

Created by

πŸ‡ͺπŸ‡ΈSpain oskar_calvo

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

Comments & Activities

  • Issue created by @oskar_calvo
  • πŸ‡©πŸ‡ͺGermany antares89 Schwerin

    Hey,
    I also had this error. With a Drupal 10.1.5 and Tome 1.13
    I noticed ObjectAwareSerialization was added with Drupal 11. Tome 1.13 adds Drupal 11 compatibility.
    After I downgraded Tome to 1.12 it worked again with Drupal 10.

  • niharika.s β†’ made their first commit to this issue’s fork.

  • πŸ‡ΊπŸ‡ΈUnited States patrick.thurmond@gmail.com Overland Park, KS

    Changing versions does not solve this. There is a problem where the PhpSerialize class is SUPPOSED to be implementing this ObjectAwareSerializationInterface in core but it is not. (ref: https://api.drupal.org/api/drupal/core%21lib%21Drupal%21Component%21Seri...)

    When you actually look at this code in Drupal 10 core.

    So instead of accepting THAT particular interface, you can fallback to just the "SerializationInterface" interface. And the reason being is that the new interface extends this interface. So it SHOULD allow for any that inherit from it.

    To fix this you need to change this file:

    In it add the following use statement at the top:

    use Drupal\Component\Serialization\SerializationInterface;
    

    Then change the constructor to say:

      /**
       * Constructs a StaticCache object.
       *
       * @param \Drupal\Core\Database\Connection $connection
       *   The database connection.
       * @param \Drupal\Core\Cache\CacheTagsChecksumInterface $checksum_provider
       *   The cache tags checksum provider.
       * @param \Drupal\Component\Serialization\SerializationInterface|int|string|null $serializer
       *   (optional) The serializer to use.
       * @param \Drupal\Component\Datetime\TimeInterface|int|string|null $time
       *   The time service.
       */
      public function __construct(Connection $connection, CacheTagsChecksumInterface $checksum_provider, SerializationInterface $serializer, TimeInterface $time) {
        DeprecationHelper::backwardsCompatibleCall(\Drupal::VERSION, '11.0.0',
          fn() => parent::__construct($connection, $checksum_provider, 'tome_static', $serializer, $time, self::MAXIMUM_NONE),
          fn() => parent::__construct($connection, $checksum_provider, 'tome_static', self::MAXIMUM_NONE)
        );
      }
    

    I am able to enable the module now AND run the static generator. I will work to create a patch to submit later after I get done dealing with the fire this caused with our failover system.

  • πŸ‡ΊπŸ‡ΈUnited States patrick.thurmond@gmail.com Overland Park, KS

    Ok, here is my patch.

  • πŸ‡ΊπŸ‡ΈUnited States patrick.thurmond@gmail.com Overland Park, KS

    I will point out that my site is on Drupal 10.2.10.

    In Drupal 9.5 the PhpSerialize class implements the "SerializationInterface".

    https://api.drupal.org/api/drupal/core%21lib%21Drupal%21Component%21Seri...

    This is apparently still the case until Drupal 10.3.x.

    For maximum compatibility I recommend implementing my solution.

Production build 0.71.5 2024