summary refs log tree commit diff
diff options
context:
space:
mode:
authorHillery Shay <shaysquared@gmail.com>2021-09-28 09:13:23 -0700
committerGitHub <noreply@github.com>2021-09-28 09:13:23 -0700
commit0f007fe009dde43a3a85aacee12cd51cd603bd1c (patch)
tree8d4123fe6224bc3343f4a11bd914fce6d5dff99f
parentDrop backwards-compatibility support for "outlier" (#10903) (diff)
downloadsynapse-0f007fe009dde43a3a85aacee12cd51cd603bd1c.tar.xz
Update utility code to handle C implementations of frozendict (#10902)
* update _handle_frozendict to work with c implementations of frozen dict

* add changelog

* add clarifying comment to _handle_frozendict
-rw-r--r--changelog.d/10902.misc1
-rw-r--r--synapse/util/__init__.py8
2 files changed, 8 insertions, 1 deletions
diff --git a/changelog.d/10902.misc b/changelog.d/10902.misc
new file mode 100644
index 0000000000..2cd79887f6
--- /dev/null
+++ b/changelog.d/10902.misc
@@ -0,0 +1 @@
+Update utility code to handle C implementations of frozendict.
\ No newline at end of file
diff --git a/synapse/util/__init__.py b/synapse/util/__init__.py
index bd234549bd..64daff59df 100644
--- a/synapse/util/__init__.py
+++ b/synapse/util/__init__.py
@@ -50,7 +50,13 @@ def _handle_frozendict(obj: Any) -> Dict[Any, Any]:
     if type(obj) is frozendict:
         # fishing the protected dict out of the object is a bit nasty,
         # but we don't really want the overhead of copying the dict.
-        return obj._dict
+        try:
+            return obj._dict
+        except AttributeError:
+            # When the C implementation of frozendict is used,
+            # there isn't a `_dict` attribute with a dict
+            # so we resort to making a copy of the frozendict
+            return dict(obj)
     raise TypeError(
         "Object of type %s is not JSON serializable" % obj.__class__.__name__
     )