Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Commit

Permalink
Unfreeze event before serializing with ujson
Browse files Browse the repository at this point in the history
In newer versions of https://github.com/esnme/ultrajson, ujson does not
serialize frozendicts (introduced in ultrajson/ultrajson@53f85b1). Although
the PyPI version is still 1.35, Fedora ships with a build from commit
ultrajson/ultrajson@2f1d487. This causes the serialization to fail if the
distribution-provided package is used.

This runs the event through the unfreeze utility before serializing it.

Thanks to @ignatenkobrain for tracking down the root cause.

fixes #2351

Signed-off-by: Jeremy Cline <[email protected]>
  • Loading branch information
jeremycline committed Sep 30, 2017
1 parent b4fd710 commit cafb8de
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion synapse/handlers/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
from synapse.util.async import run_on_reactor, ReadWriteLock, Limiter
from synapse.util.logcontext import preserve_fn
from synapse.util.metrics import measure_func
from synapse.util.frozenutils import unfreeze
from synapse.visibility import filter_events_for_client

from ._base import BaseHandler
Expand Down Expand Up @@ -503,7 +504,7 @@ def handle_new_client_event(

# Ensure that we can round trip before trying to persist in db
try:
dump = ujson.dumps(event.content)
dump = ujson.dumps(unfreeze(event.content))
ujson.loads(dump)
except:
logger.exception("Failed to encode content: %r", event.content)
Expand Down

0 comments on commit cafb8de

Please sign in to comment.