Template name "" is not valid after upgrade to Symfony2.3 #518

Closed
priestor opened this Issue Aug 1, 2013 · 14 comments

Projects

None yet

5 participants

@priestor
priestor commented Aug 1, 2013

Hello Folks!

I've updated to Symfony 2.3 and now my RestBundle doesn't work as it did before.

This an example of my code:

    $view = View::create()
        ->setStatusCode(200)
        ->setData(array_values($data->toArray()));

    $context = new SerializationContext();
    $context->setVersion('2.1');
    $context->setGroups(array('list_detail', 'list'));
    $view->setSerializationContext($context);

   $this->get('fos_rest.view_handler')->handle($view);

This did the job, giving me a nice and clean json output.

But now I'm getting that error:
"Template name "" is not valid (format is "bundle:section:template.format.engine").
500 Internal Server Error - InvalidArgumentException"

This is the config:
fos_rest:
routing_loader:
default_format: json
view:
mime_types:
json: ['application/json; charset=UTF-8', 'application/json']
view_response_listener: false
failed_validation: HTTP_BAD_REQUEST
default_engine: php
formats:
json: true
format_listener:
prefer_extension: false
body_listener:
decoders:
json: fos_rest.decoder.json

using these packages:
"jms/serializer": "0.13.@dev",
"jms/serializer-bundle": "0.12.
@dev",
"friendsofsymfony/rest-bundle": "0.13.*@dev",

Any clue what causes this problem? :(
Thank you!

@lsmith77
Member
lsmith77 commented Aug 2, 2013

can you pastebin your request on the HTTP level?

@Tjorriemorrie

My problem might be related. Any help will be greatly appreciated!

Since upgrading to 2.3.2

stackoverflow

@Tjorriemorrie

I managed to resolve mine by setting the listener to false:

stackoverflow updated

@lsmith77
Member
lsmith77 commented Aug 4, 2013

the issue is likely not caused by Symfony2.3 but by using the latest master version of FOSRestBundle that switched to a different library for content negotiation

/cc @willdurand

@willdurand
Member

The only issue I can see here is that _format is not handled, but I don't know why. IMO there is nothing wrong except the use of _format itself...

@priestor
priestor commented Aug 5, 2013

Hello, sorry for the delay.
It was a realy urgent issue in my case. I had to use a backup of an old stage and just updated the serializer packages. So it runs again as it should.

But the issue is still there. What excacly do you mean by "_format is not handled"?

Greetings

@willdurand
Member

You set prefer_extension to false, so there is no issue here. Look at your Accept header and you will see that rendering html makes the most sense in your case. Turn prefer_extension to true if you want to get JSON again.

@lsmith77
Member

ping

@priestor

Hi I'm sorry could not find some time to set up a playground with the state of the issue. I'm trying but the days still have only 24h :)

@smartinsalmeida

@lsmith77 same error with 0.12.0

"jms/serializer-bundle": "dev-master",
"friendsofsymfony/rest-bundle": "0.12.*@dev",

Then latest master version of FOSRestBundle that switched to a different library for content negotiation does not seem to be the problem at his own

Hope it helps

@lsmith77
Member

The issue is the accept header. you must either send application/json; charset=UTF-8 or application/json as the Accept header in your request

@lsmith77
Member

Alternatively prefer_extension needs to be enabled and then you can simply add a .json to your route pattern.

@smartinsalmeida

OK maybe some cache after modifying the fos rest version in composer.json.
All working as expected.

@lsmith77 lsmith77 closed this Aug 13, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment