Problem/Motivation

After updating to 3.22, I'm getting an Internal Server Error:

"errors": [
{
"title": "Internal Server Error",
"status": "500",
"detail": "Unexpected value for parameter \"sort\": expecting \"array\", got \"string\".",

Steps to reproduce

Example URL causing the error:

https://example.com/jsonapi/my_entity_type?&filter[author.id][value]=34e...

It seems like the new type hints for D10 won't accept the "short" form in string form, which is allowed according to the docs.

Proposed resolution

Allow the short form for sorts to be used again.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

ptmkenny created an issue. See original summary.

avioli’s picture

Issue is coming from jsonapi_extras/modules/jsonapi_defaults/src/Controller/EntityResource.php at line 82:

$sort = Sort::createFromQueryParameter($request->query->all('sort'))->fields();

The sort parameter must be a string as per the JSON:API spec and apparently InputBag:all($key) doesn't convert a string into an array, but throws the said exception if the value is not an array.

bbrala’s picture

Priority: Normal » Critical

Hmm, that umseems like an painfull error. Will have a look at this today.

bbrala’s picture

Hmm, i've just tried to reproduce this, but cannot, running default instalation, filtering on node articles. Can you give a little more info? What version of d10, what kind of node? Do you have jsonapi config enabled?

bbrala’s picture

Priority: Critical » Major
daveiano’s picture

I got the same Problem:

API Call: /api/node/events?sort=field_date.value

UnexpectedValueException: Unexpected value for parameter \"sort\": expecting \"array\", got \"string\". in /web/core/lib/Drupal/Core/Http/InputBag.php:31

I am using Drupal 9.4.8 with jsonapi_extras 8.x-3.22

marysmech’s picture

Same problem here.

  • drupal: 9.4.8
  • jsonapi extras: 8.x-3.22


API: /jsonapi/node/slider?sort=field_priority

Unexpected value for parameter \"sort\": expecting \"array\", got \"string\".

bbrala’s picture

Ok, will try and have a look ASAP.

ptmkenny’s picture

Also noting that I observed this error on 9.4.8.

bbrala’s picture

Hmm, i've beeen trying to reproduce this on a fresh install, but i'm having no success in that really.

From what i can see from the code, it might be an issue around changes in the interface for ->all('key'), this is probably not possible in older drupal versions, and is possible for newer. I'm going into that rabithole right now.

bbrala’s picture

Seems like there is no reason to make ->all calls, not on 9. and also not in Drupal 10 (symfony 6+). I've attached a patch that should fix this. Could you guys see how that goes?

ptmkenny’s picture

@bbrala Thank you, I can confirm the patch fixes the error on 9.4.8. Unfortunately my testing right now is limited to clicking around because my end-to-end tests are broken due to refactoring, so it would be great if other people could also confirm this.

bojan_dev’s picture

Status: Active » Reviewed & tested by the community

I could also reproduce it on 9.4.8, the patch resolves the issue, @bbrala TY!

bbrala’s picture

Status: Reviewed & tested by the community » Fixed

Tests are green, since this is major i'll do a quick release. I've also added a regression test which prooves the fix. Yay.

Now i kinda need to fix DrupalCi at some point :(

  • bbrala committed 4bb19be on 8.x-3.x
    Issue #3322635 by bbrala, ptmkenny, marysmech, avioli, bojan_dev,...
bbrala’s picture

Releasing as 3.23

Status: Fixed » Closed (fixed)

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