Opened 18 years ago

Closed 18 years ago

Last modified 18 years ago

#2183 closed enhancement (fixed)

Empty posts are still posts

Reported by: jdunck@… Owned by: Adrian Holovaty
Component: Generic views Version: 0.90
Severity: minor Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

When posting a form with no successful controls, request.POST evaluates to false in a boolean context. This causes the POST action to not be handled.

It'd be nice to still handle the post requests.

(Work around is to have a dummy form input or to name the submit button in the HTML.)

Change History (7)

comment:1 by Malcolm Tredinnick, 18 years ago

The two options that I see for fixing this are to (1) make the MultiValueDict return True whenever the request type is POST, or (2) improve the documentation to say that if you are posting a form with no data in it, you also need to check request.METAREQUEST_TYPE in your view function. Testing request.POST for "truth" is only an idiom, not compulsory.

I'm not sure I have a strong opinion one way or the other here. Listing the options for now for the benefit of future explorers.

comment:2 by James Bennett, 18 years ago

A couple of concerns to take into consideration: http://tinyurl.com/gx287 (link goes to post on django-users)

comment:3 by anonymous, 18 years ago


From: James Bennett <ubernostrum@…>
Date: Jun 17, 2006 8:25 PM
Subject: Re: POST to view loses POST data
To: django-users@…

On 6/17/06, Malcolm Tredinnick <malcolm@…> wrote:

There is already a way to test for posts via the request object:
request.METAREQUEST_METHOD. But your suggestion is not unreasonable,
so best to file a ticket so that it can be considered without being
forgotten.

I'm not convinced that it'd be a good thing to have request.POST
evaluate to True in these cases, but the reasoning is somewhat
pedantic.

First and foremost, there's a logical difference between the request
method and the request parameters, so it makes sense that a test for
the method could evaluate to True while a test for the parameters
could evaluate to False.

Second, since request.POST is supposed to be a "dictionary-like"
object, this would be unintuitive and, dare I say, "magical" behavior
-- an empty dictionary is False.

And, of course, there are practical considerations; if I want a view
to return particular output when someone POSTs with no content, now
instead of the expected "if not request.POST" -- checking for an empty
dictionary -- I have to come up with other tests like looking at the
length of request.POST to see if it's "empty but True". Again this is
unintuitive.

comment:4 by Adrian Holovaty, 18 years ago

Resolution: fixed
Status: newclosed

Fixed in [3164] with the introduction of request.method.

comment:5 by Adrian Holovaty, 18 years ago

I debated making request.method a magic object that would let you check via attribute access, as some syntactic sugar:

if request.method.POST:

...but I decided that would be too magic, and it would actually get in the way of people doing stuff like:

if request.method in ('GET', 'POST')

A plain string will do.

comment:6 by anonymous, 18 years ago

Component: Core frameworkGeneric views
milestone: Version 0.93
priority: lowlowest
Severity: normalminor
Type: defectenhancement
Version: 0.9

comment:7 by Adrian Holovaty, 18 years ago

milestone: Version 0.93

Milestone Version 0.93 deleted

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