api-platform / core

The server component of API Platform: hypermedia and GraphQL APIs in minutes
https://api-platform.com
MIT License
2.44k stars 868 forks source link

AbstractNormalizer tries to instanciate Dunglas\ApiBundle\JsonLd\Serializer\ItemNormalizer during denormalization #259

Closed Drachenkaetzchen closed 9 years ago

Drachenkaetzchen commented 9 years ago

Hi,

I'm running this bundle from about 2015-07-15 14:19:51. I try to denormalize a complex entity, and to my surprise, it fails with the following message:

"Catchable Fatal Error: Argument 1 passed to Dunglas\ApiBundle\JsonLd\Serializer\ItemNormalizer::__construct() must implement interface Dunglas\ApiBundle\Api\ResourceCollectionInterface, none given, called in /home/felicitus/public_html/PartKeepr/vendor/symfony/symfony/src/Symfony/Component/Serializer/Normalizer/AbstractNormalizer.php on line 347 and defined"

This only occurs within the manufacturers property. The distributors property works just fine.

The backtrace can be found here: http://pastebin.ca/3152210

The relevant backtrace line starts at line number 30 in the paste.

I've spent several hours trying to figure out why, but I'm pretty puzzled at this point.

dunglas commented 9 years ago

The problem is probably related with object_to_populate being null or an empty object (line 31 of the trace). It will crash anyway with such data (an object as value is mandatory).

However there is something strange the line 347 in AbstractNormalizer doesn't exist (at least in Symfony 2.7): https://github.com/symfony/symfony/blob/2.7/src/Symfony/Component/Serializer/Normalizer/AbstractNormalizer.php

Drachenkaetzchen commented 9 years ago

How can I debug this further? I already tried some debug statements, but didn't get to an conclusion why this happens.

In my project, line 347 in AbstractNormalizer is like 343 in Sf2.7. I probably should upgrade my system, however, I'm afraid that this will break as there were several changes. Or should I be safe to upgrade to the 1.0 branch of DunglasApiBundle?

dunglas commented 9 years ago

Downgrading to the 1.0 branch looks like the best idea for now because many BC breaks will occur in dev-master.

If the error persist with 1.0, can you dump the content of the context passed to the normalizer here: https://github.com/dunglas/DunglasApiBundle/blob/1.0/Controller/ResourceController.php#L88?

Drachenkaetzchen commented 9 years ago

I have finally upgraded to dev-master and the issue has gone away. Still I have no clue where this came from, but it works now.