Opened 16 years ago
Closed 15 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: | no | UI/UX: | no |
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 by , 16 years ago
Component: | Uncategorized → HTTP handling |
---|---|
Keywords: | QueryDict added |
comment:2 by , 16 years ago
comment:3 by , 15 years ago
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 by , 15 years ago
Resolution: | → worksforme |
---|---|
Status: | new → closed |
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.
This appears to only happen if no file was uploaded. If a file was uploaded, then has_key() behaves as expected.