Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix APIClient.get() when path contains unicode arguments #4458

Merged
merged 1 commit into from Sep 2, 2016

Conversation

diox
Copy link
Contributor

@diox diox commented Sep 2, 2016

If the URL contains unicode arguments, APIClient and APIRequestFactory .get() cause an exception to be raised when the request query dict is accessed, because we end up with an unicode QUERY_STRING and that's not what django expects.

Without this patch (which is adapted from django), the test I've added fails with:

tests/test_testing.py:252: in test_request_factory_url_arguments_with_unicode
    self.assertEqual(dict(request.GET), {'demo': [u'testé']})
../../.virtualenvs/drf-testing/local/lib/python2.7/site-packages/django/utils/functional.py:35: in __get__
    res = instance.__dict__[self.name] = self.func(instance)
../../.virtualenvs/drf-testing/local/lib/python2.7/site-packages/django/core/handlers/wsgi.py:124: in GET
    return http.QueryDict(raw_query_string, encoding=self._encoding)
../../.virtualenvs/drf-testing/local/lib/python2.7/site-packages/django/http/request.py:398: in __init__
    value = value.decode(encoding)
../../.virtualenvs/drf-testing/lib/python2.7/encodings/utf_8.py:16: in decode
    return codecs.utf_8_decode(input, errors, True)
E   UnicodeEncodeError: 'ascii' codec can't encode character u'\xe9' in position 4: ordinal not in range(128)

@diox diox force-pushed the fix-apiclient-get-with-unicode-url branch from f952376 to f01d013 Compare Sep 2, 2016
@tomchristie tomchristie added this to the 3.4.7 Release milestone Sep 2, 2016
@tomchristie
Copy link
Member

tomchristie commented Sep 2, 2016

This is great.
Thanks!

@tomchristie tomchristie merged commit 07efbdb into encode:master Sep 2, 2016
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants