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?
Comments
Comment #2
vensiresIn 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 headerContent-type: application/jsongets 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:
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).Comment #3
vensiresSetting this back to
Majorsince 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'ssupportsNormalizationmethod even if\Symfony\Component\Serializer\Normalizer\NormalizerInterfacedoesn't mention it. To avoid breaking anything, I get this $context and validate it usingfunc_get_arg()instead of expecting it in the method's parameters.Comment #4
jjsanzThe solutions works for me.
Comment #6
philippze commentedThe patch from #3 breaks 2 Unittests.
Comment #7
laravz commentedI believe the solution provided in patch #3 has been added to version 3 of subrequests. Does not solve the issue in our case though.
Comment #8
wylbur commentedAlso confirming we are seeing similar errors while using the 3.0.3 branch of the module.
Comment #9
mglamanI'm going to mark this a duplicate of #3270171: Notice: Undefined index: sub-content-type in Drupal\subrequests\Normalizer\MultiresponseJsonNormalizer->normalize()
Comment #10
mglamanI'm going to set as "Needs more info" since the other issue was merged.