Opened 7 years ago

Closed 7 years ago

#11036 closed (worksforme)

QueryDict has_key() calls __getitem__ instead of __contains__

Reported by: Ben Smith Owned by: nobody
Component: HTTP handling Version: 1.0
Severity: Keywords: QueryDict
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

Description

When I try to something like:

if request.FILES.has_key('key'):

....

If the key does not exist, an exception is raised. Looking at the stack trace, I see that getitem was called. Shouldn't has_key map to contains?

Change History (4)

comment:1 Changed 7 years ago by Ben Smith

Component: UncategorizedHTTP handling
Keywords: QueryDict added
Needs documentation: unset
Needs tests: unset
Patch needs improvement: unset

comment:2 Changed 7 years ago by Ben Smith

This appears to only happen if no file was uploaded. If a file was uploaded, then has_key() behaves as expected.

comment:3 Changed 7 years ago by Adam Nelson

has_key() is looking for a key (hence getitem()), not a value. contains() would be looking for a value ... or am I missing something?

comment:4 Changed 7 years ago by Chris Beaven

Resolution: worksforme
Status: newclosed
In [1]: from django.http import QueryDict

In [2]: q = QueryDict('')

In [3]: q.has_key('fish')
Out[3]: False
Note: See TracTickets for help on using tickets.
Back to Top