mirror of
https://git.anonymousland.org/anonymousland/synapse.git
synced 2024-10-01 11:49:51 -04:00
Make LoggingContext's name optional (#9857)
Fixes https://github.com/matrix-org/synapse-s3-storage-provider/issues/55
This commit is contained in:
parent
bdb4c20dc1
commit
d9bd62f9d1
1
changelog.d/9857.bugfix
Normal file
1
changelog.d/9857.bugfix
Normal file
@ -0,0 +1 @@
|
|||||||
|
Fix a regression in Synapse v1.32.1 which caused `LoggingContext` errors in plugins.
|
@ -258,7 +258,8 @@ class LoggingContext:
|
|||||||
child to the parent
|
child to the parent
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
name (str): Name for the context for debugging.
|
name: Name for the context for logging. If this is omitted, it is
|
||||||
|
inherited from the parent context.
|
||||||
parent_context (LoggingContext|None): The parent of the new context
|
parent_context (LoggingContext|None): The parent of the new context
|
||||||
"""
|
"""
|
||||||
|
|
||||||
@ -277,12 +278,11 @@ class LoggingContext:
|
|||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
name: str,
|
name: Optional[str] = None,
|
||||||
parent_context: "Optional[LoggingContext]" = None,
|
parent_context: "Optional[LoggingContext]" = None,
|
||||||
request: Optional[ContextRequest] = None,
|
request: Optional[ContextRequest] = None,
|
||||||
) -> None:
|
) -> None:
|
||||||
self.previous_context = current_context()
|
self.previous_context = current_context()
|
||||||
self.name = name
|
|
||||||
|
|
||||||
# track the resources used by this context so far
|
# track the resources used by this context so far
|
||||||
self._resource_usage = ContextResourceUsage()
|
self._resource_usage = ContextResourceUsage()
|
||||||
@ -314,6 +314,15 @@ class LoggingContext:
|
|||||||
# the request param overrides the request from the parent context
|
# the request param overrides the request from the parent context
|
||||||
self.request = request
|
self.request = request
|
||||||
|
|
||||||
|
# if we don't have a `name`, but do have a parent context, use its name.
|
||||||
|
if self.parent_context and name is None:
|
||||||
|
name = str(self.parent_context)
|
||||||
|
if name is None:
|
||||||
|
raise ValueError(
|
||||||
|
"LoggingContext must be given either a name or a parent context"
|
||||||
|
)
|
||||||
|
self.name = name
|
||||||
|
|
||||||
def __str__(self) -> str:
|
def __str__(self) -> str:
|
||||||
return self.name
|
return self.name
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user