Problem/Motivation
We are going through CloudFlare and we enabled their feature "Query String Sort". It's very useful, mostly for the search, because the query string parameters are always sorted alphabetically and you keep the number of combinations of the query string parameters to minimum. So for example the following requests:
?a=value&c=value&d=value&b=value
?b=value&d=value&c=value&a=value
?d=value&c=value&b=value&a=value
...
Will become one particular request
?a=value&b=value&c=value&d=value
So what happens with batch processing, if the query string sorting is enabled? Let's use real batch request:
/batch?id=18&op=do_nojs&op=do&_format=json
When sorting query string parameters, the request is turned to:
/batch?_format=json&id=18&op=do&op=do_nojs
And this results in error:
{"message":"Not acceptable format: json"}
Your larger batches are not fully processed. Why is this caused? The problem is that by reordering query string parameters Drupal thinks that operation is suddenly "do_nojs" and not "do", since it is now last one in the query string. So in the _batch_page() function in the switch it goes to "do_nojs" case and thus it ends up throwing exception in:
web/core/lib/Drupal/Core/EventSubscriber/AcceptNegotiation406.php:32
Full error message:
Symfony\Component\HttpKernel\Exception\NotAcceptableHttpException: Not acceptable format: json in Drupal\Core\EventSubscriber\AcceptNegotiation406->onViewDetect406() (Line 32 in /web/core/lib/Drupal/Core/EventSubscriber/AcceptNegotiation406.php).
Batch should not be dependent on the order of query string parameters. Because currently with specific server configuration (or by using some external services), which reorders query string parameters, your batch processing won't work anymore.
Steps to reproduce
Add site to cloudflare with query sorting turned on and run a batch.
Proposed resolution
Make it independent of query parameter order.
Remaining tasks
Write tests.
User interface changes
N/A
Introduced terminology
N/A
API changes
N/A
Data model changes
N/A
Release notes snippet
N/A