summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorswatantra <swatantra.kumar8@gmail.com>2019-08-09 13:49:18 +0530
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2019-08-11 20:15:23 +0200
commit73ac9e3f04c4a1a6b1add05c207d11c8ff461b7d (patch)
treec748a1de5869e45f2bf0f9c0149150d802cd6b6b
parentc1b26c77a94c13b350d80e9a2f8d0393dee737cd (diff)
Fixed #30677 -- Improved error message for urlencode() and Client when None is passed as data.
-rw-r--r--django/test/client.py4
-rw-r--r--django/utils/http.py9
-rw-r--r--tests/test_client/tests.py8
-rw-r--r--tests/utils_tests/test_http.py4
4 files changed, 13 insertions, 12 deletions
diff --git a/django/test/client.py b/django/test/client.py
index e8e4e0c6f8..9b3fdf5936 100644
--- a/django/test/client.py
+++ b/django/test/client.py
@@ -193,8 +193,8 @@ def encode_multipart(boundary, data):
for (key, value) in data.items():
if value is None:
raise TypeError(
- 'Cannot encode None as POST data. Did you mean to pass an '
- 'empty string or omit the value?'
+ "Cannot encode None for key '%s' as POST data. Did you mean "
+ "to pass an empty string or omit the value?" % key
)
elif is_file(value):
lines.extend(encode_file(boundary, key, value))
diff --git a/django/utils/http.py b/django/utils/http.py
index b6a78184a6..050375832c 100644
--- a/django/utils/http.py
+++ b/django/utils/http.py
@@ -113,8 +113,8 @@ def urlencode(query, doseq=False):
for key, value in query:
if value is None:
raise TypeError(
- 'Cannot encode None in a query string. Did you mean to pass '
- 'an empty string or omit the value?'
+ "Cannot encode None for key '%s' in a query string. Did you "
+ "mean to pass an empty string or omit the value?" % key
)
elif not doseq or isinstance(value, (str, bytes)):
query_val = value
@@ -130,8 +130,9 @@ def urlencode(query, doseq=False):
for item in itr:
if item is None:
raise TypeError(
- 'Cannot encode None in a query string. Did you '
- 'mean to pass an empty string or omit the value?'
+ "Cannot encode None for key '%s' in a query "
+ "string. Did you mean to pass an empty string or "
+ "omit the value?" % key
)
elif not isinstance(item, bytes):
item = str(item)
diff --git a/tests/test_client/tests.py b/tests/test_client/tests.py
index 84d245c05e..ce9ce40de5 100644
--- a/tests/test_client/tests.py
+++ b/tests/test_client/tests.py
@@ -61,8 +61,8 @@ class ClientTest(TestCase):
def test_get_data_none(self):
msg = (
- 'Cannot encode None in a query string. Did you mean to pass an '
- 'empty string or omit the value?'
+ "Cannot encode None for key 'value' in a query string. Did you "
+ "mean to pass an empty string or omit the value?"
)
with self.assertRaisesMessage(TypeError, msg):
self.client.get('/get_view/', {'value': None})
@@ -102,8 +102,8 @@ class ClientTest(TestCase):
def test_post_data_none(self):
msg = (
- 'Cannot encode None as POST data. Did you mean to pass an empty '
- 'string or omit the value?'
+ "Cannot encode None for key 'value' as POST data. Did you mean "
+ "to pass an empty string or omit the value?"
)
with self.assertRaisesMessage(TypeError, msg):
self.client.post('/post_view/', {'value': None})
diff --git a/tests/utils_tests/test_http.py b/tests/utils_tests/test_http.py
index c843bc9062..d1a1243ace 100644
--- a/tests/utils_tests/test_http.py
+++ b/tests/utils_tests/test_http.py
@@ -14,8 +14,8 @@ from django.utils.http import (
class URLEncodeTests(SimpleTestCase):
cannot_encode_none_msg = (
- 'Cannot encode None in a query string. Did you mean to pass an '
- 'empty string or omit the value?'
+ "Cannot encode None for key 'a' in a query string. Did you mean to "
+ "pass an empty string or omit the value?"
)
def test_tuples(self):