Problem/Motivation

In MultiresponseJsonNormalizer, lines 19-20 we have a weird setting of $headers variable and it cause PHP notices in dblog:

    // Prepare the root content type header.
    $headers = ['Content-Type' => 'application/json'];
    $headers = ['X-Sub-Content-Type' => $context['sub-content-type']];

Proposed resolution

Fix this issue in the code.

CommentFileSizeAuthor
#7 3270171-undefined-index.patch860 bytesuditrawat
Command icon 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

quadrexdev created an issue. See original summary.

quadrexdev’s picture

Assigned: quadrexdev » Unassigned
Status: Active » Needs review

I've created a merge request with a fix. Please, review.

e0ipso’s picture

Status: Needs review » Needs work
quadrexdev’s picture

Status: Needs work » Needs review

I've fixed this issue, thanks for highlighting it.

joachim’s picture

Status: Needs review » Reviewed & tested by the community

I'm seeing this in a custom JSON endpoint where we're returning a Drupal\rest\ResourceResponse.

Patch fixes the problem.

uditrawat’s picture

Version: 3.0.3 » 3.0.7
StatusFileSize
new860 bytes

Updated patch for version 3.0.7

binnythomas’s picture

The fix @#7@ works for me.

joachim’s picture

Updated the MR.

mglaman’s picture

How could sub-content-type be empty? It should be populated by \Drupal\subrequests\Blueprint\BlueprintManager::negotiateSubContentType.

The bug seems to be in \Drupal\subrequests\Normalizer\MultiresponseJsonNormalizer::supportsNormalization normalizing things it shouldn't be. That's why the context doesn't match.

mglaman’s picture

mglaman’s picture

Closed #3096577: Multiresponse normalizer invalid headers "sub-content-type" as a duplicate, I can't copy over an issue credits but it'd be nice to incorporate those folks into this ticket.

I think the root fix is still in supportsNormalization. Not normalize, since the $context is maldformed.

mglaman’s picture

Version: 3.0.7 » 3.x-dev
Status: Reviewed & tested by the community » Needs review

I've opened https://git.drupalcode.org/project/subrequests/-/merge_requests/22

Based on the related issues, the problem seems to occur when there is an empty array being normalized.

    if (count($responses) !== count($data)) {
      return FALSE;
    }

e0ipso credited jjsanz.

e0ipso credited LaravZ.

e0ipso credited philippze.

e0ipso credited smanhoff.

e0ipso credited vensires.

e0ipso credited wylbur.

e0ipso’s picture

Status: Needs review » Reviewed & tested by the community

This looks good!

I am adding issue credit as suggested above.

  • e0ipso committed c25a92da on 3.x authored by mglaman
    Issue #3270171 by quadrexdev, mglaman, joachim, uditrawat, e0ipso,...
e0ipso’s picture

Status: Reviewed & tested by the community » Fixed

Status: Fixed » Closed (fixed)

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