summary refs log tree commit diff
path: root/synapse/storage/pusher.py
diff options
context:
space:
mode:
authorErik Johnston <erik@matrix.org>2015-04-29 19:41:14 +0100
committerErik Johnston <erik@matrix.org>2015-04-29 19:41:14 +0100
commitb1ca784aca44270f21e23489541802eb5b9707b1 (patch)
treeffb03f8f6b38c01173e736bf03d046fc6c9c3612 /synapse/storage/pusher.py
parentpushkey' are also bytes. (diff)
downloadsynapse-b1ca784aca44270f21e23489541802eb5b9707b1.tar.xz
Correctly decode, for sqlite and postgres, rows from pushers table
Diffstat (limited to '')
-rw-r--r--synapse/storage/pusher.py43
1 files changed, 24 insertions, 19 deletions
diff --git a/synapse/storage/pusher.py b/synapse/storage/pusher.py
index 752b451c46..08ea62681b 100644
--- a/synapse/storage/pusher.py
+++ b/synapse/storage/pusher.py
@@ -22,11 +22,33 @@ from syutil.jsonutil import encode_canonical_json
 
 import logging
 import simplejson as json
+import types
 
 logger = logging.getLogger(__name__)
 
 
 class PusherStore(SQLBaseStore):
+    def _decode_pushers_rows(self, rows):
+        for r in rows:
+            dataJson = r['data']
+            r['data'] = None
+            try:
+                if isinstance(dataJson, types.BufferType):
+                    dataJson = str(dataJson).decode("UTF8")
+
+                r['data'] = json.loads(dataJson)
+            except Exception as e:
+                logger.warn(
+                    "Invalid JSON in data for pusher %d: %s, %s",
+                    r['id'], dataJson, e.message,
+                )
+                pass
+
+            if isinstance(r['pushkey'], types.BufferType):
+                r['pushkey'] = str(r['pushkey']).decode("UTF8")
+
+        return rows
+
     @defer.inlineCallbacks
     def get_pushers_by_app_id_and_pushkey(self, app_id, pushkey):
         def r(txn):
@@ -38,10 +60,7 @@ class PusherStore(SQLBaseStore):
             txn.execute(sql, (app_id, pushkey,))
             rows = self.cursor_to_dict(txn)
 
-            for r in rows:
-                r['pushkey'] = str(r['pushkey']).decode("UTF8")
-
-            return rows
+            return self._decode_pushers_rows(rows)
 
         rows = yield self.runInteraction(
             "get_pushers_by_app_id_and_pushkey", r
@@ -55,21 +74,7 @@ class PusherStore(SQLBaseStore):
             txn.execute("SELECT * FROM pushers")
             rows = self.cursor_to_dict(txn)
 
-            for r in rows:
-                dataJson = r['data']
-                r['data'] = None
-                try:
-                    r['data'] = json.loads(str(dataJson).decode("UTF8"))
-                except Exception as e:
-                    logger.warn(
-                        "Invalid JSON in data for pusher %d: %s, %s",
-                        r['id'], dataJson, e.message,
-                    )
-                    pass
-
-                r['pushkey'] = str(r['pushkey']).decode("UTF8")
-
-            return rows
+            return self._decode_pushers_rows(rows)
 
         rows = yield self.runInteraction("get_all_pushers", get_pushers)
         defer.returnValue(rows)