From 70c044db8efabacf3deaf8635d98c593b722541a Mon Sep 17 00:00:00 2001 From: Eric Eastwood Date: Thu, 2 Oct 2025 13:21:37 -0500 Subject: [PATCH] Remove deprecated `LoggingContext.set_current_context`/`LoggingContext.current_context` methods (#18989) These were added for backwards compatibility (and essentially deprecated) in https://github.com/matrix-org/synapse/pull/7408 (2020-05-04) because [`synapse-s3-storage-provider`](https://github.com/matrix-org/synapse-s3-storage-provider) previously relied on them -- but `synapse-s3-storage-provider` since been [updated](https://github.com/matrix-org/synapse-s3-storage-provider/pull/36) to no longer use them. --- changelog.d/18989.removal | 1 + synapse/logging/context.py | 42 -------------------------------------- 2 files changed, 1 insertion(+), 42 deletions(-) create mode 100644 changelog.d/18989.removal diff --git a/changelog.d/18989.removal b/changelog.d/18989.removal new file mode 100644 index 0000000000..356b9ffe3a --- /dev/null +++ b/changelog.d/18989.removal @@ -0,0 +1 @@ +Remove deprecated `LoggingContext.set_current_context`/`LoggingContext.current_context` methods which already have equivalent bare methods in `synapse.logging.context`. diff --git a/synapse/logging/context.py b/synapse/logging/context.py index 42fc7148c1..1b9c770311 100644 --- a/synapse/logging/context.py +++ b/synapse/logging/context.py @@ -33,7 +33,6 @@ See doc/log_contexts.rst for details on how this works. import logging import threading import typing -import warnings from types import TracebackType from typing import ( TYPE_CHECKING, @@ -378,47 +377,6 @@ class LoggingContext: def __str__(self) -> str: return self.name - @classmethod - def current_context(cls) -> LoggingContextOrSentinel: - """Get the current logging context from thread local storage - - This exists for backwards compatibility. ``current_context()`` should be - called directly. - - Returns: - The current logging context - """ - warnings.warn( - "synapse.logging.context.LoggingContext.current_context() is deprecated " - "in favor of synapse.logging.context.current_context().", - DeprecationWarning, - stacklevel=2, - ) - return current_context() - - @classmethod - def set_current_context( - cls, context: LoggingContextOrSentinel - ) -> LoggingContextOrSentinel: - """Set the current logging context in thread local storage - - This exists for backwards compatibility. ``set_current_context()`` should be - called directly. - - Args: - context: The context to activate. - - Returns: - The context that was previously active - """ - warnings.warn( - "synapse.logging.context.LoggingContext.set_current_context() is deprecated " - "in favor of synapse.logging.context.set_current_context().", - DeprecationWarning, - stacklevel=2, - ) - return set_current_context(context) - def __enter__(self) -> "LoggingContext": """Enters this logging context into thread local storage""" logcontext_debug_logger.debug("LoggingContext(%s).__enter__", self.name)