From 18ec89d49ea1606d6036022c643c09962eab676d Mon Sep 17 00:00:00 2001 From: Erik Johnston Date: Sat, 9 May 2026 13:54:14 +0100 Subject: [PATCH] Use room_version capability for state-DAG checks MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Replace `isinstance(event, FrozenEventVMSC4242)` with `event.room_version.msc4242_state_dags` in the two places where the class check was used as a state-DAG capability check. This is the more correct mental model — the relevant question is whether the room version uses state DAGs, not which Python subclass we happen to have constructed — and it lets the next commit drop `FrozenEventVMSC4242` along with the rest of the class hierarchy. A `cast(FrozenEventVMSC4242, event)` keeps mypy happy until the Rust `Event` is wired in and gains a real `prev_state_events` getter. --- synapse/handlers/message.py | 6 +++--- synapse/state/__init__.py | 5 +++-- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/synapse/handlers/message.py b/synapse/handlers/message.py index 0687c9fa79..f55a73c160 100644 --- a/synapse/handlers/message.py +++ b/synapse/handlers/message.py @@ -22,7 +22,7 @@ import logging import random from http import HTTPStatus -from typing import TYPE_CHECKING, Any, Mapping, Optional, Sequence +from typing import TYPE_CHECKING, Any, Mapping, Optional, Sequence, cast from canonicaljson import encode_canonical_json @@ -1871,8 +1871,8 @@ class EventCreationHandler: state_entry = await self.state.resolve_state_groups_for_events( event.room_id, - event_ids=event.prev_state_events - if isinstance(event, FrozenEventVMSC4242) + event_ids=cast(FrozenEventVMSC4242, event).prev_state_events + if event.room_version.msc4242_state_dags else event.prev_event_ids(), ) diff --git a/synapse/state/__init__.py b/synapse/state/__init__.py index 2f0e3f2c3e..40b2ac3c75 100644 --- a/synapse/state/__init__.py +++ b/synapse/state/__init__.py @@ -29,6 +29,7 @@ from typing import ( Mapping, Optional, Sequence, + cast, ) import attr @@ -314,8 +315,8 @@ class StateHandler: # their states - but I don't think that really matters; it just means we # might redundantly recalculate the state for this event later.) prev_event_ids = frozenset( - event.prev_state_events - if isinstance(event, FrozenEventVMSC4242) + cast(FrozenEventVMSC4242, event).prev_state_events + if event.room_version.msc4242_state_dags else event.prev_event_ids() ) incomplete_prev_events = await self.store.get_partial_state_events(