Opened 2 years ago

Closed 2 years ago

#22799 closed Cleanup/optimization (fixed)

GET and POST on HttpRequest should be QueryDicts

Reported by: duncan@… Owned by: duncan
Component: HTTP handling Version: master
Severity: Normal Keywords:
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: yes
Needs tests: no Patch needs improvement: yes
Easy pickings: no UI/UX: no

Description

On a new HttpRequest object, GET and POST are are empty dictionaries when they really ought to be QueryDicts. This is not something you would usually notice causing trouble in production as you get a WSGIRequest instead of an HttpRequest, but in testing using the test client, calling .getlist on GET or POST for a request with no get/post data results in an AttributeError.

I've made a pull request to change this: https://github.com/django/django/pull/2778

Change History (5)

comment:1 Changed 2 years ago by anonymous

Needs documentation: unset
Needs tests: unset
Patch needs improvement: unset
Type: UncategorizedBug

comment:2 Changed 2 years ago by Baptiste Mispelon

Needs documentation: set
Patch needs improvement: set
Triage Stage: UnreviewedAccepted
Type: BugCleanup/optimization

Hi,

This seems like a reasonable feature to add.

I've left a comment on the pull request and on top of that, you should also add a mention in the release notes for 1.8.

Thanks.

comment:3 Changed 2 years ago by duncan

Owner: changed from nobody to duncan
Status: newassigned

comment:4 Changed 2 years ago by duncan

I've updated the pull request in line with bmispelon's suggestions, let me know if there is anything else you need.

Cheers,

Duncan

comment:5 Changed 2 years ago by Tim Graham <timograham@…>

Resolution: fixed
Status: assignedclosed

In fd4ccd045cf8edf0bf10ee0c576c7b7c5819170c:

Fixed #22799 -- Made GET and POST on HttpRequest QueryDicts, and FILES a MultiValueDict.

Previously, GET, POST, and FILES on an HttpRequest were created in
the init method as dictionaries. This was not something you would
usually notice causing trouble in production as you'd only see a
WSGIRequest, but in testing using the test client, calling .getlist
on GET, POST, or FILES for a request with no get/post data resulted in
an AttributeError.

Changed GET and POST on an HttpRequest object to be mutable
QueryDicts (mutable because the Django tests, and probably many
third party tests, were expecting it).

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