Problem/Motivation

While running the 3.x branch on Drupal 9, the following error is encountered:

Fatal error: Declaration of Drupal\csv_serialization\Encoder\CsvEncoder::encode($data, string $format, array $context = Array): string must be compatible with Symfony\Component\Serializer\Encoder\EncoderInterface::encode($data, $format, array $context = Array) in /var/lib/tugboat/stm/web/modules/contrib/csv_serialization/src/Encoder/CsvEncoder.php on line 125

This is due to the difference in EncoderInterface::encode() signatures between Symfony 4.4 (D9) and Symfony 6.2 (D10).

Proposed resolution

Is there a way to support both or do we need to drop support for Drupal 9 on the 3.x branch?

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

markdorison created an issue. See original summary.

markdorison’s picture

Issue summary: View changes
markdorison’s picture

Title: Drop support for PHP 7.4 now that it is EOL » CsvEncoder::encode must be compatible with Symfony\Component\Serializer\Encoder\EncoderInterface::encode
Category: Task » Bug report
Issue summary: View changes
Priority: Normal » Major
markdorison’s picture

Conversation in Drupal Slack seems to confirm that dropping D9 support from the 3.x branch is the way to go.

These are one of the few times a major version bump is needed in contrib, and it's hard. Simple Oauth had same problem

yes, all the serializer stuff has been a quite painful. as there already is a 3.x release, it probably makes sense to just make that d10+

markdorison’s picture

Status: Active » Needs review

  • markdorison committed f9083374 on 3.x
    Issue #3344110 by markdorison: CsvEncoder::encode must be compatible...
markdorison’s picture

Status: Needs review » Fixed

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

andras_szilagyi’s picture

In symfony 6.2 the signature is:
public function encode(mixed $data, string $format, array $context = []): string
while in csv_serialization the signature:
public function encode($data, string $format, array $context = []):string

shouldn't we fix this?

markdorison’s picture

@Andras If you'd like to create a new issue with an MR for that change, I would be happy to review.

tonytheferg’s picture

This not being in the 3.x release causes WSOD on Drupal 9 installations.
Fatal error: Declaration of Drupal\csv_serialization\Encoder\CsvEncoder::encode($data, string $format, array $context = []): string must be compatible with Symfony\Component\Serializer\Encoder\EncoderInterface::encode($data, $format, array $context = []) in /var/www/html/web/modules/contrib/csv_serialization/src/Encoder/CsvEncoder.php on line 125

ddev composer require 'drupal/csv_serialization:^3.0' -W

installed beta.

$ ddev composer require 'drupal/csv_serialization:^3.0' -W
./composer.json has been updated
Running composer update drupal/csv_serialization --with-all-dependencies
Gathering patches for root package.
Loading composer repositories with package information
Updating dependencies
Lock file operations: 0 installs, 2 updates, 0 removals
  - Upgrading doctrine/deprecations (v1.1.0 => v1.1.1)
  - Upgrading drupal/csv_serialization (2.1.0 => 3.0.0-beta1)
Writing lock file
Installing dependencies from lock file (including require-dev)
Package operations: 0 installs, 2 updates, 0 removals
  - Downloading doctrine/deprecations (v1.1.1)
  - Downloading drupal/csv_serialization (3.0.0-beta1)
Gathering patches for root package.
Gathering patches for dependencies. This might take a minute.
  - Upgrading doctrine/deprecations (v1.1.0 => v1.1.1): Extracting archive
  - Upgrading drupal/csv_serialization (2.1.0 => 3.0.0-beta1): Extracting archive
Package doctrine/reflection is abandoned, you should avoid using it. Use roave/better-reflection instead.
Package php-http/message-factory is abandoned, you should avoid using it. Use psr/http-factory instead.
Package symfony/debug is abandoned, you should avoid using it. Use symfony/error-handler instead.
Package webmozart/path-util is abandoned, you should avoid using it. Use symfony/filesystem instead.
Generating autoload files
100 packages you are using are looking for funding.
Use the `composer fund` command to find out more!
No security vulnerability advisories found
markdorison’s picture

@tonytheferg: That beta release must incorrectly declared support for Drupal 9. If you run composer require drupal/csv_serialization:^2.0 || ^3.0 is that beta release still installed?

Version 3.0 is not compatible with Drupal 9. It is not possible to support both Drupal 9.x and 10.x in a single release of this module due to a breaking change in EncoderInterface::encode() between Symfony 4.4 (D9) and Symfony 6.2 (D10). When preparing for an upgrade to Drupal 10 we recommend that you widen your Composer version constraints to allow either 2.x or 3.x: composer require drupal/csv_serialization:^2.0 || ^3.0. This will allow the module to be automatically upgraded when you upgrade Drupal core.

tonytheferg’s picture

I'll check, that makes sense. Thanks. 👍

bcdev’s picture

I was getting issues upgrading this module to 3.0 when using a D9 install (currently moving to D10 but needed to upgrade this first). I was seeing the same error when running a drush updatedb:

Unable to decode output into JSON: Syntax error
Fatal error: Declaration of Drupal\csv_serialization\Encoder\CsvEncoder::encode($data, string $format, array $context = []): string must be compatible with Symfony\Component\Serializer\Encoder\EncoderInterface::encode($data, $format, array $context = []) in /var/www/html/web/modules/composer/csv_serialization/src/Encoder/CsvEncoder.php on line 125   

Using the composer require drupal/csv_serialization:^2.0 || ^3.0 command allowed me to get past this and I'm assuming that this will work for D10 also once I start that upgrade process.

webdrips’s picture

Thanks for the tip @bcdev, that worked for me :)

aiphes’s picture

Hello
Thanks @bcdev, applied your tips and seem to be ok now.

bwoods’s picture

Just a followup for #15 – you will want to include ^2.0 || ^3.0 directly in your composer file. Running the listed command will just require 2.0, since composer sees the pipes as a new command. The module will still show in Upgrade Status as needing to be updated, but at least it should be prepped to upgrade after the move to D10.

texas-bronius’s picture

StatusFileSize
new228.27 KB

Echoing @bwoods in #18 the instructions given in https://www.drupal.org/project/upgrade_status read:
composer require drupal/csv_serialization:^2.0 || ^3.0
whereas actually we need the quotes like:
composer require 'drupal/csv_serialization:^2.0 || ^3.0'
or composer.json will not be updated as you'd expect.
Further, if you're already on 2.1, you shouldn't specify just 2.0 but ^2.1 || ^3.0 I think. Maybe the best move is less specific, since we don't yet _know_ what the 3.x version will be at the time of finally pulling the trigger: ^2.1 || ^3. Is this message dictated by this module or something else?

screenshot showing upgrade_status for csv_serialization

markdorison’s picture

composer require 'drupal/csv_serialization:^2.0 || ^3.0'

Needing to wrap quotes around the module and version probably depends on what shell you are running but the quotes should provide extra safety. Thank you for noting it!

Further, if you're already on 2.1, you shouldn't specify just 2.0 but ^2.1 || ^3.0 I think.

It shouldn't matter. The caret allows all non-breaking (non-major) releases so specifying ^2.0 will allow 2.1 and should not downgrade you. That said, feel free to specify 2.1, if you are already on at least 2.1 there is no harm in it!

Maybe the best move is less specific, since we don't yet _know_ what the 3.x version will be at the time of finally pulling the trigger: ^2.1 || ^3

Specifying ^3.0 or ^3 should result in the same compatibility.

nicolas s.’s picture

I propose this patch to fix error when drush cr

nicolas s.’s picture

StatusFileSize
new1.29 KB
nicolas s.’s picture

nicolas s.’s picture

StatusFileSize
new1.31 KB
nicolas s.’s picture

StatusFileSize
new1.32 KB
nicolas s.’s picture

StatusFileSize
new1.74 KB
muthukris’s picture

#19 works perfectly. Thanks @texas-bronius.

dianacastillo’s picture

this doesnt work for D10 because the 3xdev doesnt work for d10 and the 4.0 version has the same issue still

fox mulder’s picture

StatusFileSize
new1.68 KB

patch for ^4.0, I didn't test it