#35915: QueryDict __getitem__ returns an empty list when the value is an empty 
list
-------------------------------------+-------------------------------------
     Reporter:  Nguyễn Hồng Quân     |                    Owner:  Ayush
         Type:                       |  Khatri
  Cleanup/optimization               |                   Status:  assigned
    Component:  HTTP handling        |                  Version:  5.1
     Severity:  Normal               |               Resolution:
     Keywords:  querydict            |             Triage Stage:  Accepted
    Has patch:  0                    |      Needs documentation:  0
  Needs tests:  0                    |  Patch needs improvement:  0
Easy pickings:  0                    |                    UI/UX:  0
-------------------------------------+-------------------------------------
Comment (by Sarah Boyce):

 Replying to [comment:3 jburns6789]:
 > QueryDict.__getitem__(key)¶
 > Returns the value for the given key. If the key has more than one value,
 it returns the last value. Raises
 django.utils.datastructures.MultiValueDictKeyError if the key does not
 exist. (This is a subclass of Python’s standard KeyError, so you can stick
 to catching KeyError.)
 >
 > I need to state when a QueryDict['key'] returns [ ], the said key is
 associated with a empty list?

 Yes
 I would be tempted to update this to be very similar to the doc string so
 maybe
 {{{#!diff
 diff --git a/docs/ref/request-response.txt b/docs/ref/request-response.txt
 index afebd00d8b..abdf75984d 100644
 --- a/docs/ref/request-response.txt
 +++ b/docs/ref/request-response.txt
 @@ -554,11 +554,10 @@ a subclass of dictionary. Exceptions are outlined
 here:

  .. method:: QueryDict.__getitem__(key)

 -    Returns the value for the given key. If the key has more than one
 value,
 -    it returns the last value. Raises
 -    ``django.utils.datastructures.MultiValueDictKeyError`` if the key
 does not
 -    exist. (This is a subclass of Python's standard :exc:`KeyError`, so
 you can
 -    stick to catching ``KeyError``.)
 +    Returns the last data value for the given key, or ``[]`` if it's an
 empty
 +    list. Raises ``django.utils.datastructures.MultiValueDictKeyError``
 if the
 +    key does not exist. (This is a subclass of Python's standard
 +    :exc:`KeyError`, so you can stick to catching ``KeyError``.)

  .. method:: QueryDict.__setitem__(key, value)
 }}}
-- 
Ticket URL: <https://code.djangoproject.com/ticket/35915#comment:5>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion visit 
https://groups.google.com/d/msgid/django-updates/010701934a85b3bb-fef5cf05-05fe-4693-884f-7afa01d7e322-000000%40eu-central-1.amazonses.com.

Reply via email to