From a5819f7da9a28e8807585bee7741f285d49e51e1 Mon Sep 17 00:00:00 2001 From: Azrenbeth <7782548+Azrenbeth@users.noreply.github.com> Date: Mon, 27 Sep 2021 15:09:09 +0100 Subject: Extract dsn parameters earlier --- synapse/storage/database.py | 8 ++------ synapse/util/state_compressor.py | 6 +++--- 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/synapse/storage/database.py b/synapse/storage/database.py index f5fb1a33de..7f94cb00d6 100644 --- a/synapse/storage/database.py +++ b/synapse/storage/database.py @@ -19,7 +19,6 @@ from collections import defaultdict from sys import intern from time import monotonic as monotonic_time from typing import ( - TYPE_CHECKING, Any, Callable, Collection, @@ -53,9 +52,6 @@ from synapse.storage.background_updates import BackgroundUpdater from synapse.storage.engines import BaseDatabaseEngine, PostgresEngine, Sqlite3Engine from synapse.storage.types import Connection, Cursor -if TYPE_CHECKING: - from psycopg2.extensions import ConnectionInfo - # python 3 does not have a maximum int value MAX_TXN_ID = 2 ** 63 - 1 @@ -435,9 +431,9 @@ class DatabasePool: # We store the connection info for later use when using postgres # (primarily to allow things like the state auto compressor to connect # to the DB). - self.postgres_connection_info: Optional["ConnectionInfo"] = None + self.postgres_connection_info_parameters: Optional[Dict] = None if isinstance(self.engine, PostgresEngine): - self.postgres_connection_info = db_conn.info + self.postgres_connection_info_parameters = db_conn.info.dsn_parameters if self.engine.can_native_upsert: # Check ASAP (and then later, every 1s) to see if we have finished diff --git a/synapse/util/state_compressor.py b/synapse/util/state_compressor.py index 93236733f7..7239554d48 100644 --- a/synapse/util/state_compressor.py +++ b/synapse/util/state_compressor.py @@ -69,11 +69,11 @@ def setup_state_compressor(hs: "HomeServer"): # parameters that rust doesn't understand, so we need to filter them out. # # Note: we need to connect to the *state* database. - conn_info = hs.get_datastores().state.db_pool.postgres_connection_info - assert conn_info is not None + conn_info_params = hs.get_datastores().state.db_pool.postgres_connection_info_parameters + assert conn_info_params is not None effective_db_args = {} - for key, value in conn_info.dsn_parameters.items(): + for key, value in conn_info_params.items(): if key in _VALID_POSTGRES_CONN_ARGS: effective_db_args[key] = value -- cgit 1.4.1