[Django] #36278: MultiValueDict should use sentinel for default values

11 views
Skip to first unread message

Django

unread,
Mar 26, 2025, 11:39:25 AM3/26/25
to django-...@googlegroups.com
#36278: MultiValueDict should use sentinel for default values
-------------------------------------+-------------------------------------
Reporter: pebl-work | Type:
| Uncategorized
Status: new | Component:
| Uncategorized
Version: 5.1 | Severity: Normal
Keywords: MultiValueDict | Triage Stage:
sentinel | Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
MultiValueDict has many methods that has a 'default' parameter, but sets
the default to None. fx:
https://github.com/django/django/blob/main/django/utils/datastructures.py#L147

This makes
mvdict.getlist('key', None)
return [], instead of the expected None.
--
Ticket URL: <https://code.djangoproject.com/ticket/36278>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Mar 26, 2025, 11:40:51 AM3/26/25
to django-...@googlegroups.com
#36278: MultiValueDict should use sentinel for default values
-------------------------------------+-------------------------------------
Reporter: pebl-work | Owner: (none)
Type: Uncategorized | Status: new
Component: Uncategorized | Version: 5.1
Severity: Normal | Resolution:
Keywords: MultiValueDict | Triage Stage:
sentinel | Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Description changed by pebl-work:

Old description:

> MultiValueDict has many methods that has a 'default' parameter, but sets
> the default to None. fx:
> https://github.com/django/django/blob/main/django/utils/datastructures.py#L147
>
> This makes
> mvdict.getlist('key', None)
> return [], instead of the expected None.

New description:

MultiValueDict has many methods that has a 'default' parameter, but sets
the default to None. fx:
https://github.com/django/django/blob/main/django/utils/datastructures.py#L129

This makes
mvdict.getlist('key', None)
return [], instead of the expected None.

--
--
Ticket URL: <https://code.djangoproject.com/ticket/36278#comment:1>

Django

unread,
Mar 26, 2025, 11:50:53 AM3/26/25
to django-...@googlegroups.com
#36278: MultiValueDict should use sentinel for default values
-------------------------------------+-------------------------------------
Reporter: pebl-work | Owner: (none)
Type: Uncategorized | Status: new
Component: Uncategorized | Version: 5.1
Severity: Normal | Resolution:
Keywords: MultiValueDict | Triage Stage:
sentinel | Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Comment (by Simon Charette):

Assuming we want to change this behavior we'd have to go through a
deprecation period as there might be code out there that expects `[]` to
be returned from `getlist(missing_key, None)`.
--
Ticket URL: <https://code.djangoproject.com/ticket/36278#comment:2>

Django

unread,
Mar 26, 2025, 3:53:59 PM3/26/25
to django-...@googlegroups.com
#36278: MultiValueDict should use sentinel for default values
-------------------------------------+-------------------------------------
Reporter: Peter Larsen - | Owner: (none)
Puzzel Solutions |
Type: New feature | Status: closed
Component: Utilities | Version: dev
Severity: Normal | Resolution: wontfix
Keywords: MultiValueDict | Triage Stage:
getlist default | Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Natalia Bidart):

* component: Uncategorized => Utilities
* keywords: MultiValueDict sentinel => MultiValueDict getlist default
* resolution: => wontfix
* status: new => closed
* type: Uncategorized => New feature
* version: 5.1 => dev

Comment:

I don't think we should change this. The behavior is exactly as
[https://docs.djangoproject.com/en/5.1/ref/request-
response/#django.http.QueryDict.getlist documented] for, `QueryDict`:

> Returns a list of the data with the requested key. Returns an empty list
if the key doesn’t exist and default is None. It’s guaranteed to return a
list unless the default value provided isn’t a list.

It makes sense to me that `getlist` should always return a list. The
intended usage is either to pass a non-`None` default or expect an empty
list as the result. Changing the semantics of default would be a new
feature, requiring not only a deprecation period but also community
consensus.

(Note that `MultiValueDict`, on its own, is not a documented nor public
data structure to reuse. It's the base structure for `QueryDict` and
that's the behavior I'm analyzing and prioritizing with this triage.)
--
Ticket URL: <https://code.djangoproject.com/ticket/36278#comment:3>
Reply all
Reply to author
Forward
0 new messages