Opened 8 years ago

Closed 8 years ago

Last modified 8 years ago

#5138 closed (fixed)

Add __contains__ to HttpRequest to make it more dict-like

Reported by: anonymous Owned by: nobody
Component: Uncategorized Version: master
Severity: Keywords:
Cc: Triage Stage: Design decision needed
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

Description

If I try to evaluate the view method

def index(request):
    if 'foo' in request: ...

I the error "0 not found in either POST or GET." Adding the following method to HttpRequest

def __contains__(self, key):
    return self.has_key(key)

fixes that problem. Please add that method to make the request behavior more dict-like.

Attachments (1)

HttpRequest-contains.patch (533 bytes) - added by robbie@… 8 years ago.
Patch to add contains method to HttpResquest

Download all attachments as: .zip

Change History (7)

comment:1 Changed 8 years ago by Simon G. <dev@…>

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Summary changed from in operator doesn't work with HttpRequest to Add __contains__ to HttpRequest to make it more dict-like
  • Triage Stage changed from Unreviewed to Design decision needed

comment:3 Changed 8 years ago by robbie@…

  • Has patch set

This caught me out as well today. I think it's a good idea to enable, and then promote, the use of "in" over the "has_key" method since dict.has_key() is being depreciated.

I'm also attaching a patch to achieve this.

Changed 8 years ago by robbie@…

Patch to add contains method to HttpResquest

comment:4 Changed 8 years ago by russellm

(In [6097]) Fixed #5138 -- Added contains method to HttpRequest, mirroring existing has_key method. Thanks for the patch, robbie@…. NOTE: Original checkin message incorrectly referenced bug #5318.

comment:5 Changed 8 years ago by russellm

  • Resolution set to fixed
  • Status changed from new to closed

comment:6 Changed 8 years ago by russellm

(In [6098]) Refs #5138 -- Refactored implementation of contains in HttpRequest introduced in [6097] after a suggestion from Malcolm. Applied a similar refactor for MergeDict and Context which had comparable behavior.

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