Code

Opened 5 years ago

Closed 5 years ago

#11036 closed (worksforme)

QueryDict has_key() calls __getitem__ instead of __contains__

Reported by: bensmith 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?

Attachments (0)

Change History (4)

comment:1 Changed 5 years ago by bensmith

  • Component changed from Uncategorized to HTTP handling
  • Keywords QueryDict added
  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

comment:2 Changed 5 years ago by bensmith

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

comment:3 Changed 5 years ago by adamnelson

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 5 years ago by SmileyChris

  • Resolution set to worksforme
  • Status changed from new to closed
In [1]: from django.http import QueryDict

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

In [3]: q.has_key('fish')
Out[3]: False

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.