django-bootstrap-modal-forms icon indicating copy to clipboard operation
django-bootstrap-modal-forms copied to clipboard

BSModalDeleteView generates warning in Django 4

Open christianwgd opened this issue 3 years ago • 9 comments

Object will be deleted, but the redirection to the views success_url doesn't work. Instead you get a warning

python3.10/site-packages/django/views/generic/base.py:62: DeleteViewCustomDeleteWarning:
DeleteView uses FormMixin to handle POST requests. As a consequence, any custom deletion logic in
BlogPostDeleteView.delete() handler should be moved to form_valid().
  self = cls(**initkwargs)

Simply downgrading django to 3.2.11 makes it work again.

christianwgd avatar Jan 28 '22 11:01 christianwgd

$(".delete-book").each(function () { $(this).modalForm({formURL: $(this).data("form-url"), isDeleteForm: true}); });

Passing in isDeleteForm: true solves the problem.

lovmo avatar Feb 05 '22 00:02 lovmo

Oh, stupid me, you are completely right. Had a look in previous projects and recognised, i had done so. Thanks

christianwgd avatar Feb 05 '22 10:02 christianwgd

Sorry, I have to reopen this, although it maybe a minor issue. Deleting works fine, but the warning still appears:

DeleteViewCustomDeleteWarning: DeleteView uses FormMixin to handle POST requests. As a consequence, any custom deletion logic in ImageDeleteView.delete() handler should be moved to form_valid().
  self = cls(**initkwargs)

There's no "delete" logic in my view class.

I try to have a closer look into it.

christianwgd avatar Feb 05 '22 10:02 christianwgd

Seems to be intended behaviour: https://docs.djangoproject.com/en/4.0/releases/4.0/#generic-views and that means that in the DeleteMessageMixin the content of the delete method should be moved to the form_valid method.

I will try if this is backwards compatible with django 3 in the next days.

christianwgd avatar Feb 05 '22 10:02 christianwgd

Simply moving the content of delete to form_valid is running with django3.2 and 4.0 but breaks the tests for 3.2 und lower. Any hint to keep this compatible?

christianwgd avatar Feb 05 '22 14:02 christianwgd

Found that simply moving the logic in DeleteMessageMixin from delete to post is fully compatible with django 3.2 and django 4 and doesn't break any tests. Will send a pull request...

christianwgd avatar Apr 19 '22 18:04 christianwgd

@trco, is it possible to accept this pull request and release a new version? Thanks!

leonardodepaula avatar Aug 26 '22 23:08 leonardodepaula

Still brings the warning

Justinspryce avatar Sep 14 '22 11:09 Justinspryce

@Justinspryce Can you please describe what exactly you've tested? I just reviewed the pull request with Django 4.1 and got no warning.

christianwgd avatar Sep 15 '22 04:09 christianwgd

Closed with #216.

trco avatar May 01 '23 16:05 trco