Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
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.
Comment | File | Size | Author |
---|---|---|---|
#11 | 3322635-11.patch | 806 bytes | bbrala |
Comments
Comment #2
avioli CreditAttribution: avioli commentedIssue 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 apparentlyInputBag:all($key)
doesn't convert a string into an array, but throws the said exception if the value is not an array.Comment #3
bbralaHmm, that umseems like an painfull error. Will have a look at this today.
Comment #4
bbralaHmm, 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?
Comment #5
bbralaComment #6
daveianoI 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
Comment #7
marysmech CreditAttribution: marysmech at Freely Agency commentedSame problem here.
API: /jsonapi/node/slider?sort=field_priority
Unexpected value for parameter \"sort\": expecting \"array\", got \"string\".
Comment #8
bbralaOk, will try and have a look ASAP.
Comment #9
ptmkenny CreditAttribution: ptmkenny commentedAlso noting that I observed this error on 9.4.8.
Comment #10
bbralaHmm, 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.
Comment #11
bbralaSeems 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?
Comment #12
ptmkenny CreditAttribution: ptmkenny commented@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.
Comment #13
bojan_dev CreditAttribution: bojan_dev commentedI could also reproduce it on 9.4.8, the patch resolves the issue, @bbrala TY!
Comment #14
bbralaTests 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 :(
Comment #16
bbralaReleasing as 3.23