Don't serialize stings
This commit is contained in:
@@ -16,6 +16,10 @@ class JSONSerializer(object):
|
||||
raise SerializationError(e)
|
||||
|
||||
def dumps(self, data):
|
||||
# don't serialize strings
|
||||
if isinstance(data, (type(''), type(u''))):
|
||||
return data
|
||||
|
||||
try:
|
||||
return json.dumps(data, default=self.default)
|
||||
except (ValueError, TypeError) as e:
|
||||
|
||||
@@ -207,7 +207,7 @@ class Transport(object):
|
||||
:arg body: body of the request, will be serializes using serializer and
|
||||
passed to the connection
|
||||
"""
|
||||
if body:
|
||||
if body is not None:
|
||||
body = self.serializer.dumps(body)
|
||||
|
||||
for attempt in range(self.max_retries + 1):
|
||||
|
||||
@@ -15,3 +15,6 @@ class TestJSONSerializer(TestCase):
|
||||
self.assertRaises(SerializationError, JSONSerializer().loads, object())
|
||||
self.assertRaises(SerializationError, JSONSerializer().loads, '')
|
||||
self.assertRaises(SerializationError, JSONSerializer().loads, '{{')
|
||||
|
||||
def test_strings_are_left_untouched(self):
|
||||
self.assertEquals('Hello World!', JSONSerializer().dumps('Hello World!'))
|
||||
|
||||
@@ -3,7 +3,7 @@ from unittest import TestCase
|
||||
|
||||
from elasticsearch.transport import Transport
|
||||
from elasticsearch.connection import Connection
|
||||
from elasticsearch.exceptions import TransportError, ConnectionError
|
||||
from elasticsearch.exceptions import ConnectionError
|
||||
|
||||
class DummyConnection(Connection):
|
||||
def __init__(self, **kwargs):
|
||||
|
||||
Reference in New Issue
Block a user