Problem/Motivation

The current automated tests fail against PHP 7 branch, see https://www.drupal.org/node/2723491/qa. The issue is described by test bot here: https://www.drupal.org/pift-ci-job/678456.

It blocks issues from being tested / accepted, so I set the major priority for it.

Proposed resolution

Find out what causes the issue and fix it. The last passing build was on 13th of May, the first failure happened ay 18th of May. Assuming something had happened between those dates.

Comments

Spleshka created an issue. See original summary.

spleshka’s picture

Title: Fix failing tests with PHP7 in the dev branch » Fix failing tests with PHP7 / D8.4.x in the dev branch
spleshka’s picture

Tested with php 7.0 and php 7.1 on Drupal 8.3.x - could not reproduce the issue. Assuming it's something in Drupal 8.4.x.

e0ipso’s picture

Priority: Major » Critical

Thanks for reporting this. I think this is our current highest priority. I don't have a PHP7 environment at the moment. Maybe someone else can work on this.

spleshka’s picture

I'll get home in several hours, will take a look

spleshka’s picture

Just a note while I'm still searching for the issue: was able to reproduce the issue on both php7.0 and php7.1 with latest Drupal core 8.4.x.

spleshka’s picture

Got it: here's the issue which broke our tests: #2293697: EntityResource POST routes all use the confusing default: use entity types' https://www.drupal.org/link-relations/create link template if available. If I run tests with this commit in core - they fail. If I go 1 commit before - tests pass. Now going to think about the proper fix.

spleshka’s picture

The issue is related to the new route added in the patch:

system.4xx:
  path: '/system/4xx'
  defaults:
   _controller: '\Drupal\system\Controller\Http4xxController:on4xx'
    _title: 'Client error'
  requirements:
    _access: 'TRUE'

So instead of json response, Drupal returns html with rendered 4xx page. Trying to find a good solution (all ideas are welcome)

spleshka’s picture

So now DefaultExceptionHtmlSubscriber implements method on4xx(), which eventually returns the html page:

public function on4xx(GetResponseForExceptionEvent $event) {
  if (($exception = $event->getException()) && $exception instanceof HttpExceptionInterface) {
    $this->makeSubrequest($event, '/system/4xx', $exception->getStatusCode());
  }
}

I think that JSON API needs its own ExceptionSubscriber which provides the expected error handing.

spleshka’s picture

Oh, actually DefaultExceptionSubscriber exists in JSON API. Wondering then how the error handing appears inDefaultExceptionHtmlSubscriber?

spleshka’s picture

Okay, I think I know the answer to #10. We're trying to test the case when there is no Content-Type header. The request is treated as html request, and DefaultExceptionHtmlSubscriber is used instead of the one from JSON API. Since there was introduced a new method on4xx(), it simply returns its value (obviously, in html representation).

spleshka’s picture

Status: Active » Needs review
StatusFileSize
new701 bytes

The fix for this issue turns out to be simple: instead of Content-Type header we should send Accept header to indicate that we want to get response in json format.

As a follow-up, we should create an issue to highlight in documentation how important headers when it comes to errors handing.

spleshka’s picture

Fixed the same issue in several other places.

spleshka’s picture

Now all tests are passing, yay! Awaiting for manual review.

e0ipso’s picture

Status: Needs review » Reviewed & tested by the community

This looks good. I'll be merging soon.

  • e0ipso committed 407df46 on 8.x-1.x authored by Spleshka
    test(Functional): Fix failing tests with core 8.4.x (#2880987 by...
e0ipso’s picture

Status: Reviewed & tested by the community » Fixed
spleshka’s picture

Sweeeet, thanks Mateu.

wim leers’s picture

wim leers’s picture

I was also reminded of \Drupal\rest\EventSubscriber\ResourceResponseSubscriber::getResponseFormat() by the changes here, but I don't think updating \Drupal\jsonapi\EventSubscriber\ResourceResponseSubscriber would have fixed it.

On the one hand, I feel that this didn't actually fix the root cause. On the other hand, it's totally reasonable to require that a format is actually requested, i.e. that you must specify the Accept request header. It's just a continuation of what was already decided in #2831137: Remove the need for ?_format=api_json: assume the use of the 'api_json' format for routes managed by JSON API.

So: +1!

Status: Fixed » Closed (fixed)

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