Opened 5 years ago

Closed 4 years ago

#14020 closed New feature (fixed)

Make HttpResponse.get work like dict.get

Reported by: schmichael Owned by: anonymous
Component: HTTP handling Version: master
Severity: Normal Keywords:
Cc: Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no


>>> from django import http
>>> resp = http.HttpResponse()
>>> resp['Connection'] = 'close'
>>> resp.get('Connection')
Traceback (most recent call last):
  File "<console>", line 1, in <module>
TypeError: get() takes exactly 3 arguments (2 given)
>>> foo = {}
>>> foo.get('Connection')

Attachments (2)

srsly.patch (506 bytes) - added by schmichael 5 years ago.
14020_with_tests.patch (1.2 KB) - added by moopet 5 years ago.

Download all attachments as: .zip

Change History (8)

Changed 5 years ago by schmichael

comment:1 Changed 5 years ago by anonymous

  • Component changed from Uncategorized to HTTP handling
  • Needs documentation unset
  • Needs tests unset
  • Owner changed from nobody to anonymous
  • Patch needs improvement unset
  • Status changed from new to assigned
  • Triage Stage changed from Unreviewed to Ready for checkin

comment:2 Changed 5 years ago by Alex

  • Needs documentation set
  • Needs tests set
  • Triage Stage changed from Ready for checkin to Accepted

comment:3 Changed 5 years ago by julien

  • Severity set to Normal
  • Type set to New feature

Changed 5 years ago by moopet

comment:4 Changed 5 years ago by moopet

  • Easy pickings unset
  • Needs tests unset

comment:5 Changed 4 years ago by Victor van den Elzen <victor.van.den.elzen@…>

  • Needs documentation unset
  • Triage Stage changed from Accepted to Ready for checkin
  • UI/UX unset

The docs say "To set or remove a header in your response, treat it like a dictionary". So I don't think this needs more documentation.

14020_with_tests.patch is obvious, has a test, applies cleanly to r16353 and passes all tests, so IMHO it's ready for checkin.

comment:6 Changed 4 years ago by jezdez

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

In [16417]:

Fixed #14020 -- Made the HttpResponse class slightly more behave like a dictionary, allowing the alternative argument to be unset. Serious thanks to schmichael and moopet.

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