From d81f4606db9385188ba645a88fb6fb4161cf5386 Mon Sep 17 00:00:00 2001 From: mdipierro Date: Sat, 13 Sep 2014 10:35:54 -0500 Subject: [PATCH] fixed mongodb json? --- VERSION | 2 +- gluon/dal.py | 22 ++++++++++++---------- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/VERSION b/VERSION index 57afd7ac..53a1674c 100644 --- a/VERSION +++ b/VERSION @@ -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 diff --git a/gluon/dal.py b/gluon/dal.py index 7635ac57..54097f42 100644 --- a/gluon/dal.py +++ b/gluon/dal.py @@ -720,7 +720,7 @@ class BaseAdapter(ConnectionPool): __metaclass__ = AdapterMeta - driver_auto_json_loads = False + driver_auto_json = [] driver = None driver_name = None drivers = () # list of drivers from which to pick @@ -2037,13 +2037,14 @@ class BaseAdapter(ConnectionPool): else: obj = str(obj) elif fieldtype == 'json': - # always pass a string JSON string - if have_serializers: - obj = serializers.json(obj) - elif simplejson: - obj = simplejson.dumps(obj) - else: - raise RuntimeError("missing simplejson") + if not 'dumps' in self.driver_auto_json: + # always pass a string JSON string + if have_serializers: + obj = serializers.json(obj) + elif simplejson: + obj = simplejson.dumps(obj) + else: + raise RuntimeError("missing simplejson") if not isinstance(obj, bytes): obj = bytes(obj) try: @@ -2175,7 +2176,7 @@ class BaseAdapter(ConnectionPool): return float(value) 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): raise RuntimeError('json data not a string') if isinstance(value, unicode): @@ -2924,7 +2925,7 @@ class PostgreSQLAdapter(BaseAdapter): else: supports_json = None if supports_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)") def LIKE(self, first, second): @@ -5703,6 +5704,7 @@ def cleanup(text): class MongoDBAdapter(NoSQLAdapter): drivers = ('pymongo', ) + driver_auto_json_loads = ['loads','dumps'] uploads_in_blob = False