From 6d6a1c3454ae787e3878202a8e41341ddcf7bee0 Mon Sep 17 00:00:00 2001 From: Erik Johnston Date: Thu, 14 Aug 2014 14:30:25 +0100 Subject: [PATCH] Actually encode dicts as json in the DB --- synapse/storage/__init__.py | 4 ++-- synapse/storage/_base.py | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/synapse/storage/__init__.py b/synapse/storage/__init__.py index d38d61345..cd9acdc44 100644 --- a/synapse/storage/__init__.py +++ b/synapse/storage/__init__.py @@ -81,11 +81,11 @@ class DataStore(RoomDataStore, RoomMemberStore, MessageStore, RoomStore, "event_type", event.type, "sender": event.user_id, "room_id": event.room_id, - "content": event.content, + "content": json.dumps(event.content), } unrec = {k: v for k, v in event.get_full_dict() if k not in vals.keys()} - val["unrecognized_keys"] = unrec + val["unrecognized_keys"] = json.dumps(unrec) yield self._simple_insert("events", vals) diff --git a/synapse/storage/_base.py b/synapse/storage/_base.py index 489b6bd17..5cb26ad6d 100644 --- a/synapse/storage/_base.py +++ b/synapse/storage/_base.py @@ -288,7 +288,8 @@ class SQLBaseStore(object): def _parse_event_from_row(self, row_dict): d = copy.deepcopy({k: v for k, v in row.items() if v}) - d.update(json.loads(row["unrecognized_keys"])) + d.update(json.loads(json.loads(row["unrecognized_keys"]))) + d["content"] = json.loads(d["content"}) del d["unrecognized_keys"] return self.event_factory.create_event(