Opened 14 years ago

Closed 14 years ago

Last modified 13 years ago

#14558 closed (fixed)

Generic View http_method bug

Reported by: pyrou Owned by: nobody
Component: Generic views Version: dev
Severity: Keywords:
Cc: michael.hurni@… Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

In generic views, you can find some http_method alias, just like in DeleteView (inherited from DeletionMixin)

post = delete 

but if you override the orginal "delete" method in your own view :

class myDeleteView(DeleteView):
    def delete(self, request, *args, **kwargs):
        print "some console log"
        return super(DeleteView, self).delete(self, request, *args, **kwargs)

your log is never printed, because your browser will use POST method, and so the original delete method is called instead of the overriden one.

Adding everytime the alias post = delete is not "DRY-ful"..

This way seems to be more "correct" for every alias:

def post(self, *args, **kwargs):
    return self.delete(*args, **kwargs)

Attachments (1)

edit.py.diff (1.4 KB ) - added by pyrou 14 years ago.

Download all attachments as: .zip

Change History (5)

comment:1 by Łukasz Rekucki, 14 years ago

Triage Stage: UnreviewedAccepted

This is a problem. Personally, I'm not very happy with either way of aliasing, because there is no way to get rid of the alias. With the alias always there, you can't create a view that deletes on DELETE and creates a child resource on POST (which is the original meaning of that HTTP verb).

There is also an slight inconsistency in UpdateView, which aliases POST to PUT, but IMHO this is a part of a larger issue.

in reply to:  1 comment:2 by pyrou, 14 years ago

Cc: michael.hurni@… added

Replying to lrekucki:

This is a problem. Personally, I'm not very happy with either way of aliasing, because there is no way to get rid of the alias. With the alias always there, you can't create a view that deletes on DELETE and creates a child resource on POST (which is the original meaning of that HTTP verb).

There is also an slight inconsistency in UpdateView, which aliases POST to PUT, but IMHO this is a part of a larger issue.


You just have to create two methods, that will rid the "View" of its alias, it's not a problem in either way of aliasing.

class myRestUpdateView(UpdateView):
    def delete(self, request, *args, **kwargs):
        # delete
    def post(self, request, *args, **kwargs):
        # create a child ressource

The only point I want to fix is "keeping" the link between two methods when you override the original method (in my first example, the delete method)

by pyrou, 14 years ago

Attachment: edit.py.diff added

comment:3 by Russell Keith-Magee, 14 years ago

Resolution: fixed
Status: newclosed

(In [14374]) Fixed #14558 -- Modified the way PUT and DELETE HTTP methods are handled so that overridden methods will get used correctly. Thanks to pyrou for the report and patch.

comment:4 by Jacob, 13 years ago

milestone: 1.3

Milestone 1.3 deleted

Note: See TracTickets for help on using tickets.
Back to Top