From b2cd3b802fee2f15b66e02a028265ee75b4eee0f Mon Sep 17 00:00:00 2001 From: Andrew Morgan Date: Thu, 2 Mar 2023 16:58:36 +0000 Subject: [PATCH] Make _account_data_id_gen always an AbstractStreamIdGenerator to appease mypy As get_next_txn is part of AbstractStreamIdGenerator, not AbstractStreamIdTracker. I'm not sure why we insisted in trying to type it as a Tracker vs. a Generator, and then checking that elsewhere in the codebase. The init function of AccountDataWorkerStore will always create _account_data_id_gen as either a StreamIdGenerator or a MultiWriterIdGenerator. Both of which are AbstractStreamidGenerators. --- synapse/storage/databases/main/account_data.py | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/synapse/storage/databases/main/account_data.py b/synapse/storage/databases/main/account_data.py index 006e3b584739..a720d620ee60 100644 --- a/synapse/storage/databases/main/account_data.py +++ b/synapse/storage/databases/main/account_data.py @@ -39,7 +39,6 @@ from synapse.storage.engines import PostgresEngine from synapse.storage.util.id_generators import ( AbstractStreamIdGenerator, - AbstractStreamIdTracker, MultiWriterIdGenerator, StreamIdGenerator, ) @@ -63,14 +62,12 @@ def __init__( ): super().__init__(database, db_conn, hs) - # `_can_write_to_account_data` indicates whether the current worker is allowed - # to write account data. A value of `True` implies that `_account_data_id_gen` - # is an `AbstractStreamIdGenerator` and not just a tracker. - self._account_data_id_gen: AbstractStreamIdTracker self._can_write_to_account_data = ( self._instance_name in hs.config.worker.writers.account_data ) + self._account_data_id_gen: AbstractStreamIdGenerator + if isinstance(database.engine, PostgresEngine): self._account_data_id_gen = MultiWriterIdGenerator( db_conn=db_conn, @@ -475,7 +472,6 @@ async def add_account_data_to_room( The maximum stream ID. """ assert self._can_write_to_account_data - assert isinstance(self._account_data_id_gen, AbstractStreamIdGenerator) content_json = json_encoder.encode(content) @@ -514,7 +510,6 @@ async def remove_account_data_for_room( The maximum account data stream position. """ assert self._can_write_to_account_data - assert isinstance(self._account_data_id_gen, AbstractStreamIdGenerator) def _remove_account_data_for_room_txn(txn: LoggingTransaction) -> Optional[int]: """ @@ -590,7 +585,6 @@ async def add_account_data_for_user( The maximum stream ID. """ assert self._can_write_to_account_data - assert isinstance(self._account_data_id_gen, AbstractStreamIdGenerator) async with self._account_data_id_gen.get_next() as next_id: await self.db_pool.runInteraction( @@ -696,7 +690,6 @@ async def remove_account_data_for_user( The maximum account data stream position. """ assert self._can_write_to_account_data - assert isinstance(self._account_data_id_gen, AbstractStreamIdGenerator) def _remove_account_data_for_user_txn(txn: LoggingTransaction) -> Optional[int]: """