[D11] InvalidQueryException when value for unique target is an array

Created on 29 August 2024, 3 months ago
Updated 15 September 2024, 2 months ago

Problem/Motivation

When the value for a unique target happens to be an array instead of a string, you'll get a \Drupal\Core\Database\InvalidQueryException on Drupal 11.

Steps to reproduce

  1. Install Feeds Tamper.
  2. Create a feed type.
  3. Map to a field. Set the field target as 'unique'.
  4. Add the Tamper "Explode" to this field.

When importing data now, the Tamper plugin "Explode" will turn the value for the field in question into an array. This happens even if the character that is used to split the value into multiple values does not appear in the value.

Simplified code example:

$value = 'Foo';
$new_value = explode('|', $value);

$new_value will equal to ['Foo'].

On Drupal 10, this will result into a deprecation warning:

Calling Drupal\Core\Database\Query\Condition::condition() without an array compatible operator is deprecated in drupal:10.1.0 and will be required in drupal:11.0.0. See https://www.drupal.org/node/3350985

But an exception on Drupal 11:

Drupal\Core\Database\InvalidQueryException: Calling Drupal\Core\Database\Query\Condition::condition() without an array compatible operator is not supported. See https://www.drupal.org/node/3350985

Proposed resolution

Attempt to cast the value for the unique query in \Drupal\feeds\Plugin\Type\Target\FieldTargetBase::getUniqueValue() to a string before passing it to Drupal\Core\Database\Query\Condition::condition().

Remaining tasks

  • Review
  • Commit

User interface changes

None.

API changes

Using multiple values to find an existing entity will no longer be supported. Because of the change in 🐛 DBTNG/EQ condition works inconsistently with arrays Fixed this would already no longer work since Drupal 10.1. When Feeds receives multiple values, it will pick the first one on the list to find the existing entity.

Data model changes

None.

Code will follow.

🐛 Bug report
Status

Fixed

Version

3.0

Component

Code

Created by

🇳🇱Netherlands megachriz

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

Merge Requests

Comments & Activities

Production build 0.71.5 2024