Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Commit

Permalink
Fix no create event being found because no state events persisted yet
Browse files Browse the repository at this point in the history
  • Loading branch information
MadLittleMods committed Aug 21, 2021
1 parent aafa069 commit fedd250
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
1 change: 1 addition & 0 deletions synapse/handlers/federation.py
Original file line number Diff line number Diff line change
Expand Up @@ -1692,6 +1692,7 @@ async def do_invite_join(
await self.store.upsert_room_on_join(
room_id=room_id,
room_version=room_version_obj,
auth_events=auth_chain,
)

max_stream_id = await self._persist_auth_tree(
Expand Down
21 changes: 17 additions & 4 deletions synapse/storage/databases/main/room.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
from synapse.api.constants import EventTypes, JoinRules
from synapse.api.errors import StoreError
from synapse.api.room_versions import RoomVersion, RoomVersions
from synapse.events import EventBase
from synapse.storage._base import SQLBaseStore, db_to_json
from synapse.storage.database import DatabasePool, LoggingTransaction
from synapse.storage.databases.main.search import SearchStore
Expand Down Expand Up @@ -1333,7 +1334,7 @@ async def has_auth_chain_index(self, room_id: str) -> bool:
keyvalues={"room_id": room_id},
retcol="MAX(stream_ordering)",
allow_none=True,
desc="upsert_room_on_join",
desc="has_auth_chain_index_fallback",
)

return max_ordering is None
Expand Down Expand Up @@ -1410,7 +1411,9 @@ def __init__(self, database: DatabasePool, db_conn, hs):

self.config = hs.config

async def upsert_room_on_join(self, room_id: str, room_version: RoomVersion):
async def upsert_room_on_join(
self, room_id: str, room_version: RoomVersion, auth_events: List[EventBase]
):
"""Ensure that the room is stored in the table
Called when we join a room over federation, and overwrites any room version
Expand All @@ -1421,7 +1424,17 @@ async def upsert_room_on_join(self, room_id: str, room_version: RoomVersion):
# mark the room as having an auth chain cover index.
has_auth_chain_index = await self.has_auth_chain_index(room_id)

create_event = await self.store.get_create_event_for_room(room_id)
create_event = None
for e in auth_events:
if (e.type, e.state_key) == (EventTypes.Create, ""):
create_event = e
break

if create_event is None:
# If the state doesn't have a create event then the room is
# invalid, and it would fail auth checks anyway.
raise StoreError(400, "No create event in state")

room_creator = create_event.content.get("creator", None)

await self.db_pool.simple_upsert(
Expand Down Expand Up @@ -1451,7 +1464,7 @@ async def maybe_store_room_on_outlier_membership(
# mark the room as having an auth chain cover index.
has_auth_chain_index = await self.has_auth_chain_index(room_id)

create_event = await self.store.get_create_event_for_room(room_id)
create_event = await self.get_create_event_for_room(room_id)
room_creator = create_event.content.get("creator", None)

await self.db_pool.simple_upsert(
Expand Down

0 comments on commit fedd250

Please sign in to comment.