Easyadminbundle: delete an entity is not working

Created on 26 Sep 2016  路  18Comments  路  Source: EasyCorp/EasyAdminBundle

I'm trying to delete any entity, but nothing happens, the page refresh and the entity stills there, no errors are show, I think the problem is in deleteAction in easyadmin-bundle/Controller/AdminController.php
EasyAdminBundle version: 1.15.1
Symfony version: 2.8.11

bug confirmed hasPR

All 18 comments

I'm having this issue as well when trying to delete any entity (no matter if they have a foreign key relationship or not).

It seems that the $form->isValid() fails inside the deleteAction() of the AdminController. I cannot figure out is going wrong though as the ID, entity and request method are all correct.

The form does not contain any errors, so I wonder why the isValid() check fails.

Please look into it as it's quite a breaking bug.

EasyAdminBundle version: 1.15.1
Symfony version: v3.1.4

I was looking and my case fails in
if ('DELETE' !== $this->request->getMethod())
because $this->request->getMethod() returns 'POST' and 'DELETE' is expected.
I changed it but stills not working because $form->isValid() returns false like @hipio says.

@Raeghal That if-statement works fine for me, just not the form->isValid() check.

I've now simply overwritten the function and removed the isValid() check, but it's a VERY bad hack.

@javiereguiluz Could you please look into this?

It would be good to know if a PR for this would be accepted...

The issue is that the request is no DELETE request. Rather than changing the way the form is submitted you should find out why the request is a POST request and not a DELETE request.

@xabbuh I'm sending a valid DELETE request as stated in my comment. The problem is the isValid() which fails for a reason I cannot deduce.

@Potherca, I don't think that there is a PR request which fixes this issue.

@hipio What does $form->isSubmitted() return?

@xabbuh bool(true) as expected. Like I said, the problem is with the isValid()-check. I already did some debugging myself.

@hipio Sorry, confused it with https://github.com/javiereguiluz/EasyAdminBundle/issues/1306#issuecomment-251114742.

If you could provide a reproducable scenario, I could take a look into it tonight. Best would be to fork the Symfony Standard Edition and make the changes needed to reproduce it.

@xabbuh No problem! It's reproducible by just using the current release version. If needed I'll create a fork with only the basic Symfony stuff.

Well, shit. I just tried to remove an entity without including my own method and it worked just fine. I guess it was fixed in one of the previous commits or I did something that fixed it, but I have no idea what... Could be a composer update, could be something unrelated. No idea, which sucks, because that means I can't provide proper feedback.

Sorry.

Also experiencing the same problem. I'm running with Symfony v2.7.19
I've tried multiple different versions of EasyAdminBundle:

  • v1.14.0
  • v1.15.0
  • v1.15.1
  • v1.15.2

I've debugged this using v1.15.2 and I'm finding the same issue as reported earlier about the method coming in as POST rather than DELETE. If I force the request to be a DELETE then the form validates (it won't validate a POST request - which I suspect is where @Raeghal was going wrong).

Here is a hack for clarity about what I did to make it work:

        $this->dispatch(EasyAdminEvents::PRE_DELETE);

        if ('DELETE' !== $this->request->getMethod()) {
            $this->request->setMethod('DELETE');
            //return $this->redirect($this->generateUrl('easyadmin', array('action' => 'list', 'entity' => $this->entity['name'])));
        }

So that means I need to find out why the DELETE method isn't working properly. The http_method_override appears to not be working correctly in my case - I can see in the request sent in that _method: DELETE is set - suggesting this is a problem elsewhere in my Symfony set up.

I found the problem in my case was that I'm using the AppCache, and I didn't have the Request::enableHttpMethodParameterOverride() set properly on all my apps. Here is the link to the docs: http://symfony.com/doc/current/reference/configuration/framework.html#http-method-override

So in my case this wasn't a problem with the bundle! Hopefully this line of debugging can help others.

@araines It would be helpful if you could provide a reproducable scenario (for example, by cloning the Symfony Demo application and making the necessary changes). Without further information it's hard to figure out what is going wrong.

@xabbuh as I mention in my comment, I actually don't suffer from this problem. Deletes are working fine for me, my issue was with my configuration of Symfony itself when it comes to the http_method_override where I simply hadn't followed the documentation.

I cannot reproduce this problem on v1.15.1 or v1.15.2 myself, apologies.

Found disabled CSRF might be causing same symptoms: https://github.com/javiereguiluz/EasyAdminBundle/issues/1409#issuecomment-266454032

Very nice find @czeslav87, that looks like it might indeed be the problem.

Closing it as fixed by #1477 which is included in the 1.16.4 release. If the error persist, please reopen. Thanks!

Was this page helpful?
0 / 5 - 0 ratings