While using subrequests I consistently retrieve following notice "Notice: Undefined index: sub-content-type" which flushes the database.

It seems on the MultiresponseJsonNormalizer the sub-content-type is included in the headers but this is never set.

/**
 * Normalizes multiple response objects into a single string.
 */
class MultiresponseJsonNormalizer implements NormalizerInterface {

  /**
   * {@inheritdoc}
   */
  public function normalize($object, $format = NULL, array $context = []) {
    // Prepare the root content type header.
    $content_type = sprintf(
      'application/json; type=%s',
      $context['sub-content-type'],
    );
    $headers = ['Content-Type' => $content_type];

    ...

When checking existence before including this seems to be fixed. Should this be included in the first place and any idea's on why this is empty?

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

smanhoff created an issue. See original summary.

vensires’s picture

Priority: Major » Normal

In my case I, have a view with a REST display enabled using the default cookie provided and having chosen as required format the json. If the subrequests module is disabled and I try to visit a view's page without any results (eg. ?page=1000), a 200 JSON Response with no body but a proper header Content-type: application/json gets returned.

If I enable the subrequests module and visit the same page again, I get the following body instead of an empty one: {"content":"[]","headers":{"Content-Type":"application\/json; type="}}.

I also add the backtrace for my scenario:

Notice: Undefined index: sub-content-type in Drupal\subrequests\Normalizer\MultiresponseJsonNormalizer->normalize() (line 21 of modules/contrib/subrequests/src/Normalizer/MultiresponseJsonNormalizer.php).
Drupal\subrequests\Normalizer\MultiresponseJsonNormalizer->normalize(Array, 'json', Array) (Line: 143)
Symfony\Component\Serializer\Serializer->normalize(Array, 'json', Array) (Line: 116)
Symfony\Component\Serializer\Serializer->serialize(Array, 'json', Array) (Line: 142)
Drupal\rest\Plugin\views\style\Serializer->render() (Line: 450)
Drupal\rest\Plugin\views\display\RestExport->Drupal\rest\Plugin\views\display\{closure}() (Line: 573)
Drupal\Core\Render\Renderer->executeInRenderContext(Object, Object) (Line: 451)
Drupal\rest\Plugin\views\display\RestExport->render() (Line: 1533)
Drupal\views\ViewExecutable->render() (Line: 441)
Drupal\rest\Plugin\views\display\RestExport->execute() (Line: 1630)
Drupal\views\ViewExecutable->executeDisplay('list', Array) (Line: 78)
Drupal\views\Element\View::preRenderViewElement(Array)

I don't know if that's your case @smanhoff but this bug really is something annoying and without good reason I believe. I still consider it a Major bug which the isset() you suggest doesn't fix since it also adds body where it shouldn't and of a different type (eg. views originally returns array, subrequests returns object).

vensires’s picture

Priority: Normal » Major
Status: Active » Needs review
StatusFileSize
new575 bytes

Setting this back to Major since I accidentally dropped it. I also attach a patch which fixes the issue for me.

\Symfony\Component\Serializer\Serializer::getNormalizer() passes the $context parameter to each normalizer's supportsNormalization method even if \Symfony\Component\Serializer\Normalizer\NormalizerInterface doesn't mention it. To avoid breaking anything, I get this $context and validate it using func_get_arg() instead of expecting it in the method's parameters.

jjsanz’s picture

The solutions works for me.

philippze made their first commit to this issue’s fork.

philippze’s picture

The patch from #3 breaks 2 Unittests.

laravz’s picture

I believe the solution provided in patch #3 has been added to version 3 of subrequests. Does not solve the issue in our case though.

wylbur’s picture

Also confirming we are seeing similar errors while using the 3.0.3 branch of the module.

mglaman’s picture

Status: Needs review » Postponed (maintainer needs more info)

I'm going to set as "Needs more info" since the other issue was merged.