home / django_tickets / tickets

tickets: 8278

This data as json

id created changetime last_pulled_from_trac stage status component type severity version resolution summary description owner reporter keywords easy has_patch needs_better_patch needs_tests needs_docs ui_ux
8278 2008-08-13 04:32:20 2011-09-28 16:12:17 2022-03-06 03:41:49.849023 Accepted closed Core (Other)     dev fixed QueryDict.update eats data when other_dict is a MultiValueDict django.http.QueryDict supports .update, but it seems to assume that other_dict is a (builtin) dict. This is dangerous when mixing two QueryDicts. {{{ >>> x = QueryDict('a=1&a=2') >>> y = QueryDict('a=3&a=4') >>> print x <QueryDict: {u'a': [u'1', u'2']}> >>> print y <QueryDict: {u'a': [u'3', u'4']}> >>> x._mutable = True >>> x.update(y) >>> x._mutable=False >>> print x <QueryDict: {u'a': [u'1', u'2', u'4']}> }}} Note that a=3 was lost. As far as I can see, there's no really nice fix to this. QueryDict.update doesn't just defer to MultiValueDict because it needs to force keys and values into unicode. Defering to MultiValueDict first and then forcing means duplicate keys for items not yet coerced. Forcing individual items results in lists from QueryDict becoming (single) items in MultiValueDict. i.e. {{{ dict([(f(k), f(v)) for k, v in other_dict.items()]) -> dict([(f(k), [f(v) for v in values]) for k, values in other_dict.lists()]) }}} This seems to be a leaky abstraction here; I think QueryDict is not really a MultiValueDict, since MultiValueDict can have any (hashable) objects as keys and values, while QueryDict insists on unicode objects only. No patch from me since the solution isn't obvious to me. Marking as 1.0 since this is a bug, though. nobody jdunck   0 1 1 0 0 0
Powered by Datasette · Queries took 0.883ms