Opened 5 years ago

Closed 5 years ago

#27521 closed Bug (needsinfo)

QueryDict is inconsistently converted to kwargs between CPython and PyPy

Reported by: Mark Heppner Owned by: nobody
Component: Core (Other) Version: 1.10
Severity: Normal Keywords: PyPy QueryDict MultiValueDict
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

from django.conf import settings
settings.configure()
from django.http.request import QueryDict
q = QueryDict('foo=bar&foo=baz')

def test(**kwargs):
    print(kwargs)

test(**q)

In CPython 2.7, 3.4, and 3.5, this prints out {u'foo': [u'bar', u'baz']}, with the value being set to a list. In PyPy 5.4 (2.7.10) and 5.6 (2.7.12), the value comes back as a single string, always picking the last item {u'foo': u'baz'}. To clarify, the instance of QueryDict is the same between the two, they both show the value as a list; it's only different when converting to kwargs. From what I can tell, this inconsistent behavior is present in Django 1.8, 1.9, and 1.10.

In PyPy, this can be fixed by first casting to a dict:

> test(**dict(q))
{u'foo': [u'bar', u'baz']}

Change History (3)

comment:1 Changed 5 years ago by Tim Graham

Can you elaborate why Django is at fault (rather than say, PyPy) and/or propose a patch?

comment:2 in reply to:  1 Changed 5 years ago by Mark Heppner

Replying to Tim Graham:

Can you elaborate why Django is at fault (rather than say, PyPy) and/or propose a patch?

I'm not entirely sure what's going on with the internals of converting it to kwargs, so I cannot propose a patch nor am I sure if Django is even at fault.

comment:3 Changed 5 years ago by Tim Graham

Resolution: needsinfo
Status: newclosed

Okay, I'd suggest to file a bug with PyPy and reopen this ticket if they indicate that Django is at fault. Thanks.

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