File tree Expand file tree Collapse file tree 2 files changed +13
-3
lines changed Expand file tree Collapse file tree 2 files changed +13
-3
lines changed Original file line number Diff line number Diff line change 1+ Fix a regression in Synapse v1.32.1 which caused `LoggingContext` errors in plugins.
Original file line number Diff line number Diff line change @@ -258,7 +258,8 @@ class LoggingContext:
258258 child to the parent
259259
260260 Args:
261- name (str): Name for the context for debugging.
261+ name: Name for the context for logging. If this is omitted, it is
262+ inherited from the parent context.
262263 parent_context (LoggingContext|None): The parent of the new context
263264 """
264265
@@ -277,12 +278,11 @@ class LoggingContext:
277278
278279 def __init__ (
279280 self ,
280- name : str ,
281+ name : Optional [ str ] = None ,
281282 parent_context : "Optional[LoggingContext]" = None ,
282283 request : Optional [ContextRequest ] = None ,
283284 ) -> None :
284285 self .previous_context = current_context ()
285- self .name = name
286286
287287 # track the resources used by this context so far
288288 self ._resource_usage = ContextResourceUsage ()
@@ -314,6 +314,15 @@ def __init__(
314314 # the request param overrides the request from the parent context
315315 self .request = request
316316
317+ # if we don't have a `name`, but do have a parent context, use its name.
318+ if self .parent_context and name is None :
319+ name = str (self .parent_context )
320+ if name is None :
321+ raise ValueError (
322+ "LoggingContext must be given either a name or a parent context"
323+ )
324+ self .name = name
325+
317326 def __str__ (self ) -> str :
318327 return self .name
319328
You can’t perform that action at this time.
0 commit comments