Add type hints to the logging context code. (#8939)

This commit is contained in:
Patrick Cloke 2021-01-05 08:06:55 -05:00 committed by GitHub
parent 9dde9c9f01
commit 06fefe0bb1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 47 additions and 22 deletions

View file

@ -42,7 +42,6 @@ from synapse.api.errors import StoreError
from synapse.config.database import DatabaseConnectionConfig
from synapse.logging.context import (
LoggingContext,
LoggingContextOrSentinel,
current_context,
make_deferred_yieldable,
)
@ -671,12 +670,15 @@ class DatabasePool:
Returns:
The result of func
"""
parent_context = current_context() # type: Optional[LoggingContextOrSentinel]
if not parent_context:
curr_context = current_context()
if not curr_context:
logger.warning(
"Starting db connection from sentinel context: metrics will be lost"
)
parent_context = None
else:
assert isinstance(curr_context, LoggingContext)
parent_context = curr_context
start_time = monotonic_time()