fixed mongodb json?

This commit is contained in:
mdipierro
2014-09-13 10:35:54 -05:00
parent d29a108ad7
commit d81f4606db
2 changed files with 13 additions and 11 deletions
+1 -1
View File
@@ -1 +1 @@
Version 2.9.9-stable+timestamp.2014.09.12.20.28.40 Version 2.9.9-stable+timestamp.2014.09.13.10.35.47
+12 -10
View File
@@ -720,7 +720,7 @@ class BaseAdapter(ConnectionPool):
__metaclass__ = AdapterMeta __metaclass__ = AdapterMeta
driver_auto_json_loads = False driver_auto_json = []
driver = None driver = None
driver_name = None driver_name = None
drivers = () # list of drivers from which to pick drivers = () # list of drivers from which to pick
@@ -2037,13 +2037,14 @@ class BaseAdapter(ConnectionPool):
else: else:
obj = str(obj) obj = str(obj)
elif fieldtype == 'json': elif fieldtype == 'json':
# always pass a string JSON string if not 'dumps' in self.driver_auto_json:
if have_serializers: # always pass a string JSON string
obj = serializers.json(obj) if have_serializers:
elif simplejson: obj = serializers.json(obj)
obj = simplejson.dumps(obj) elif simplejson:
else: obj = simplejson.dumps(obj)
raise RuntimeError("missing simplejson") else:
raise RuntimeError("missing simplejson")
if not isinstance(obj, bytes): if not isinstance(obj, bytes):
obj = bytes(obj) obj = bytes(obj)
try: try:
@@ -2175,7 +2176,7 @@ class BaseAdapter(ConnectionPool):
return float(value) return float(value)
def parse_json(self, value, field_type): def parse_json(self, value, field_type):
if not self.driver_auto_json_loads: if not 'loads' in self.driver_auto_json:
if not isinstance(value, basestring): if not isinstance(value, basestring):
raise RuntimeError('json data not a string') raise RuntimeError('json data not a string')
if isinstance(value, unicode): if isinstance(value, unicode):
@@ -2924,7 +2925,7 @@ class PostgreSQLAdapter(BaseAdapter):
else: supports_json = None else: supports_json = None
if supports_json: if supports_json:
self.types["json"] = "JSON" self.types["json"] = "JSON"
self.driver_auto_json_loads = True self.driver_auto_json = ['loads']
else: LOGGER.debug("Your database version does not support the JSON data type (using TEXT instead)") else: LOGGER.debug("Your database version does not support the JSON data type (using TEXT instead)")
def LIKE(self, first, second): def LIKE(self, first, second):
@@ -5703,6 +5704,7 @@ def cleanup(text):
class MongoDBAdapter(NoSQLAdapter): class MongoDBAdapter(NoSQLAdapter):
drivers = ('pymongo', ) drivers = ('pymongo', )
driver_auto_json_loads = ['loads','dumps']
uploads_in_blob = False uploads_in_blob = False