Sylius/SyliusResourceBundle

LogicException when submitting invalid (empty) fields for resource creation

rimas-kudelis opened this issue · 2 comments

When I make a POST request with invalid POST data to /LOCALE/account/address-book/add, I'm getting a 500 response and a LogicException saying "Cannot check if an unsubmitted form is valid. Call Form::isSubmitted() before Form::isValid().".

This appears to be caused by line 188 in ResourceController.php, which reads as follows:

if ($request->isMethod('POST') && $form->handleRequest($request)->isValid()) {

Is there a reason why the isSubmitted() check is not performed here?

Yes I've already seen this error years ago.

On symfony demo:
if ($form->isSubmitted() && $form->isValid()) {
https://github.com/symfony/demo/blob/master/src/Controller/BlogController.php#L103

@pamil @lchrusciel I opened a pull request to fix this error.