summary refs log tree commit diff
path: root/synapse/util/logcontext.py
diff options
context:
space:
mode:
authorErik Johnston <erik@matrix.org>2016-08-23 15:23:39 +0100
committerErik Johnston <erik@matrix.org>2016-08-24 11:58:40 +0100
commit921913935176f5bd3df5e5b960d87c94a2adb304 (patch)
treeccb7c2bddbad96b35fcb0de89b562ed0a4115a67 /synapse/util/logcontext.py
parentMerge pull request #1039 from matrix-org/kegan/join-with-custom-content (diff)
downloadsynapse-921913935176f5bd3df5e5b960d87c94a2adb304.tar.xz
Preserve some logcontexts
Diffstat (limited to 'synapse/util/logcontext.py')
-rw-r--r--synapse/util/logcontext.py15
1 files changed, 11 insertions, 4 deletions
diff --git a/synapse/util/logcontext.py b/synapse/util/logcontext.py
index 7a87045f87..6c83eb213d 100644
--- a/synapse/util/logcontext.py
+++ b/synapse/util/logcontext.py
@@ -297,12 +297,13 @@ def preserve_context_over_fn(fn, *args, **kwargs):
         return res
 
 
-def preserve_context_over_deferred(deferred):
+def preserve_context_over_deferred(deferred, context=None):
     """Given a deferred wrap it such that any callbacks added later to it will
     be invoked with the current context.
     """
-    current_context = LoggingContext.current_context()
-    d = _PreservingContextDeferred(current_context)
+    if context is None:
+        context = LoggingContext.current_context()
+    d = _PreservingContextDeferred(context)
     deferred.chainDeferred(d)
     return d
 
@@ -316,7 +317,13 @@ def preserve_fn(f):
 
     def g(*args, **kwargs):
         with PreserveLoggingContext(current):
-            return f(*args, **kwargs)
+            res = f(*args, **kwargs)
+            if isinstance(res, defer.Deferred):
+                return preserve_context_over_deferred(
+                    res, context=LoggingContext.sentinel
+                )
+            else:
+                return res
     return g