Problem/Motivation
Along the course of upgrading to Drupal 10 and 11 some of our old JS pages broke - they were sending a single array filter value with a scalar operator. This worked on Drupal 9 and maybe until Drupal 11.
This results in the site returning a 500 error. However, it's properly a 400 error since it's an invalid filter, not a server error. The back-end is throwing an uncaught Drupal\Core\Database\InvalidQueryException
This is an unexpected effect of the change described in #3350985: Passing an array value to a database condition without using a compatible operator is no longer supported
This issue is somewhat related, but old:
#3063154: Assume IN operator, or return friendlier error, when provided multiple values without a specified operator
Steps to reproduce
Query using jsonapi against a field using a scalar operator and an array of values
For example (using the default = operator):
/jsonapi/node/page?filter[status][condition][path]=status&filter[status][condition][value][]=1
Results in a JSON error (local dev) like:
{"jsonapi":{"version":"1.1","meta":{"links":{"self":{"href":"https:\/\/jsonapi.org\/format\/1.1\/"}}}},"errors":[{"title":"Internal Server Error","status":"500","detail":"Calling Drupal\\Core\\Database\\Query\\Condition::condition() without an array compatible operator is not supported. See https:\/\/www.drupal.org\/node\/3350985","links":{"via":{"href":"https:\/\/vexample.com\/jsonapi\/node\/page?filter%5Bstatus%5D%5Bcondition%5D%5Bpath%5D=status\u0026filter%5Bstatus%5D%5Bcondition%5D%5Bvalue%5D%5B0%5D=1"},"info":{"href":"https:\/\/www.w3.org\/Protocols\/rfc2616\/rfc2616-sec10.html#sec10.5.1"}},"source":{"file":"\/var\/www\/drupal\/web\/core\/modules\/jsonapi\/src\/EventSubscriber\/DefaultExceptionSubscriber.php","line":49},"meta":{"exception":"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 in \/var\/www\/drupal\/web\/core\/lib\/Drupal\/Core\/Database\/Query\/Condition.php:115
Proposed resolution
In jsonapi catch an Drupal\Core\Database\InvalidQueryException and convert to a 400 error by re-throwing a \Symfony\Component\HttpKernel\Exception\BadRequestHttpException or the like
Remaining tasks
User interface changes
n/a
Introduced terminology
n/a
API changes
n/a
Data model changes
n/a
Release notes snippet
TODO
Issue fork drupal-3636601
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
Comment #2
pwolanin commentedComment #3
cilefen commented