Skip to content

Commit f3c9a16

Browse files
committed
Fixed QueryDict.setlistdefault.
It was broken by a seemingly innocuous change in MultiValueDict. Document the pitfall for now. This is fragile and should be considered for refactoring.
1 parent 69f4856 commit f3c9a16

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

django/utils/datastructures.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -339,15 +339,17 @@ def setlist(self, key, list_):
339339
def setdefault(self, key, default=None):
340340
if key not in self:
341341
self[key] = default
342-
return default
342+
# Do not return default here because __setitem__() may store
343+
# another value -- QueryDict.__setitem__() does. Look it up.
343344
return self[key]
344345

345346
def setlistdefault(self, key, default_list=None):
346347
if key not in self:
347348
if default_list is None:
348349
default_list = []
349350
self.setlist(key, default_list)
350-
return default_list
351+
# Do not return default_list here because setlist() may store
352+
# another value -- QueryDict.setlist() does. Look it up.
351353
return self.getlist(key)
352354

353355
def appendlist(self, key, value):

0 commit comments

Comments
 (0)