Skip to content

Commit d72c278

Browse files
Remove allow_no_prev_events option (MSC2716 cleanup) (#18676)
This option is no longer used since we backed out the MSC2716 changes in matrix-org/synapse#15748 and is even mentioned as a follow-up task in the PR description there. The `allow_no_prev_events` option was first introduced in matrix-org/synapse#11243 to support MSC2716 back in the day.
1 parent b274d65 commit d72c278

File tree

4 files changed

+12
-116
lines changed

4 files changed

+12
-116
lines changed

changelog.d/18676.misc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Remove unused `allow_no_prev_events` option when creating an event.

synapse/handlers/message.py

Lines changed: 5 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -568,7 +568,6 @@ async def create_event(
568568
requester: Requester,
569569
event_dict: dict,
570570
txn_id: Optional[str] = None,
571-
allow_no_prev_events: bool = False,
572571
prev_event_ids: Optional[List[str]] = None,
573572
auth_event_ids: Optional[List[str]] = None,
574573
state_event_ids: Optional[List[str]] = None,
@@ -594,10 +593,6 @@ async def create_event(
594593
requester
595594
event_dict: An entire event
596595
txn_id
597-
allow_no_prev_events: Whether to allow this event to be created an empty
598-
list of prev_events. Normally this is prohibited just because most
599-
events should have a prev_event and we should only use this in special
600-
cases (previously useful for MSC2716).
601596
prev_event_ids:
602597
the forward extremities to use as the prev_events for the
603598
new event.
@@ -717,7 +712,6 @@ async def create_event(
717712
event, unpersisted_context = await self.create_new_client_event(
718713
builder=builder,
719714
requester=requester,
720-
allow_no_prev_events=allow_no_prev_events,
721715
prev_event_ids=prev_event_ids,
722716
auth_event_ids=auth_event_ids,
723717
state_event_ids=state_event_ids,
@@ -945,7 +939,6 @@ async def create_and_send_nonmember_event(
945939
self,
946940
requester: Requester,
947941
event_dict: dict,
948-
allow_no_prev_events: bool = False,
949942
prev_event_ids: Optional[List[str]] = None,
950943
state_event_ids: Optional[List[str]] = None,
951944
ratelimit: bool = True,
@@ -962,10 +955,6 @@ async def create_and_send_nonmember_event(
962955
Args:
963956
requester: The requester sending the event.
964957
event_dict: An entire event.
965-
allow_no_prev_events: Whether to allow this event to be created an empty
966-
list of prev_events. Normally this is prohibited just because most
967-
events should have a prev_event and we should only use this in special
968-
cases (previously useful for MSC2716).
969958
prev_event_ids:
970959
The event IDs to use as the prev events.
971960
Should normally be left as None to automatically request them
@@ -1051,7 +1040,6 @@ async def create_and_send_nonmember_event(
10511040
return await self._create_and_send_nonmember_event_locked(
10521041
requester=requester,
10531042
event_dict=event_dict,
1054-
allow_no_prev_events=allow_no_prev_events,
10551043
prev_event_ids=prev_event_ids,
10561044
state_event_ids=state_event_ids,
10571045
ratelimit=ratelimit,
@@ -1065,7 +1053,6 @@ async def _create_and_send_nonmember_event_locked(
10651053
self,
10661054
requester: Requester,
10671055
event_dict: dict,
1068-
allow_no_prev_events: bool = False,
10691056
prev_event_ids: Optional[List[str]] = None,
10701057
state_event_ids: Optional[List[str]] = None,
10711058
ratelimit: bool = True,
@@ -1097,7 +1084,6 @@ async def _create_and_send_nonmember_event_locked(
10971084
requester,
10981085
event_dict,
10991086
txn_id=txn_id,
1100-
allow_no_prev_events=allow_no_prev_events,
11011087
prev_event_ids=prev_event_ids,
11021088
state_event_ids=state_event_ids,
11031089
outlier=outlier,
@@ -1180,7 +1166,6 @@ async def create_new_client_event(
11801166
self,
11811167
builder: EventBuilder,
11821168
requester: Optional[Requester] = None,
1183-
allow_no_prev_events: bool = False,
11841169
prev_event_ids: Optional[List[str]] = None,
11851170
auth_event_ids: Optional[List[str]] = None,
11861171
state_event_ids: Optional[List[str]] = None,
@@ -1200,10 +1185,6 @@ async def create_new_client_event(
12001185
Args:
12011186
builder:
12021187
requester:
1203-
allow_no_prev_events: Whether to allow this event to be created an empty
1204-
list of prev_events. Normally this is prohibited just because most
1205-
events should have a prev_event and we should only use this in special
1206-
cases (previously useful for MSC2716).
12071188
prev_event_ids:
12081189
the forward extremities to use as the prev_events for the
12091190
new event.
@@ -1241,7 +1222,6 @@ async def create_new_client_event(
12411222
if state_event_ids is not None:
12421223
# Do a quick check to make sure that prev_event_ids is present to
12431224
# make the type-checking around `builder.build` happy.
1244-
# prev_event_ids could be an empty array though.
12451225
assert prev_event_ids is not None
12461226

12471227
temp_event = await builder.build(
@@ -1269,24 +1249,14 @@ async def create_new_client_event(
12691249
else:
12701250
prev_event_ids = await self.store.get_prev_events_for_room(builder.room_id)
12711251

1252+
# We now ought to have some `prev_events` (unless it's a create event).
1253+
#
12721254
# Do a quick sanity check here, rather than waiting until we've created the
12731255
# event and then try to auth it (which fails with a somewhat confusing "No
12741256
# create event in auth events")
1275-
if allow_no_prev_events:
1276-
# We allow events with no `prev_events` but it better have some `auth_events`
1277-
assert (
1278-
builder.type == EventTypes.Create
1279-
# Allow an event to have empty list of prev_event_ids
1280-
# only if it has auth_event_ids.
1281-
or auth_event_ids
1282-
), (
1283-
"Attempting to create a non-m.room.create event with no prev_events or auth_event_ids"
1284-
)
1285-
else:
1286-
# we now ought to have some prev_events (unless it's a create event).
1287-
assert builder.type == EventTypes.Create or prev_event_ids, (
1288-
"Attempting to create a non-m.room.create event with no prev_events"
1289-
)
1257+
assert builder.type == EventTypes.Create or len(prev_event_ids) > 0, (
1258+
"Attempting to create an event with no prev_events"
1259+
)
12901260

12911261
if for_batch:
12921262
assert prev_event_ids is not None

synapse/handlers/room_member.py

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -388,11 +388,11 @@ async def ratelimit_invite(
388388

389389
async def _local_membership_update(
390390
self,
391+
*,
391392
requester: Requester,
392393
target: UserID,
393394
room_id: str,
394395
membership: str,
395-
allow_no_prev_events: bool = False,
396396
prev_event_ids: Optional[List[str]] = None,
397397
state_event_ids: Optional[List[str]] = None,
398398
depth: Optional[int] = None,
@@ -414,11 +414,6 @@ async def _local_membership_update(
414414
desired membership event.
415415
room_id:
416416
membership:
417-
418-
allow_no_prev_events: Whether to allow this event to be created an empty
419-
list of prev_events. Normally this is prohibited just because most
420-
events should have a prev_event and we should only use this in special
421-
cases (previously useful for MSC2716).
422417
prev_event_ids: The event IDs to use as the prev events
423418
state_event_ids:
424419
The full state at a given event. This was previously used particularly
@@ -486,7 +481,6 @@ async def _local_membership_update(
486481
"origin_server_ts": origin_server_ts,
487482
},
488483
txn_id=txn_id,
489-
allow_no_prev_events=allow_no_prev_events,
490484
prev_event_ids=prev_event_ids,
491485
state_event_ids=state_event_ids,
492486
depth=depth,
@@ -583,7 +577,6 @@ async def update_membership(
583577
new_room: bool = False,
584578
require_consent: bool = True,
585579
outlier: bool = False,
586-
allow_no_prev_events: bool = False,
587580
prev_event_ids: Optional[List[str]] = None,
588581
state_event_ids: Optional[List[str]] = None,
589582
depth: Optional[int] = None,
@@ -607,10 +600,6 @@ async def update_membership(
607600
outlier: Indicates whether the event is an `outlier`, i.e. if
608601
it's from an arbitrary point and floating in the DAG as
609602
opposed to being inline with the current DAG.
610-
allow_no_prev_events: Whether to allow this event to be created an empty
611-
list of prev_events. Normally this is prohibited just because most
612-
events should have a prev_event and we should only use this in special
613-
cases (previously useful for MSC2716).
614603
prev_event_ids: The event IDs to use as the prev events
615604
state_event_ids:
616605
The full state at a given event. This was previously used particularly
@@ -680,7 +669,6 @@ async def update_membership(
680669
new_room=new_room,
681670
require_consent=require_consent,
682671
outlier=outlier,
683-
allow_no_prev_events=allow_no_prev_events,
684672
prev_event_ids=prev_event_ids,
685673
state_event_ids=state_event_ids,
686674
depth=depth,
@@ -703,7 +691,6 @@ async def update_membership_locked(
703691
new_room: bool = False,
704692
require_consent: bool = True,
705693
outlier: bool = False,
706-
allow_no_prev_events: bool = False,
707694
prev_event_ids: Optional[List[str]] = None,
708695
state_event_ids: Optional[List[str]] = None,
709696
depth: Optional[int] = None,
@@ -729,10 +716,6 @@ async def update_membership_locked(
729716
outlier: Indicates whether the event is an `outlier`, i.e. if
730717
it's from an arbitrary point and floating in the DAG as
731718
opposed to being inline with the current DAG.
732-
allow_no_prev_events: Whether to allow this event to be created an empty
733-
list of prev_events. Normally this is prohibited just because most
734-
events should have a prev_event and we should only use this in special
735-
cases (previously useful for MSC2716).
736719
prev_event_ids: The event IDs to use as the prev events
737720
state_event_ids:
738721
The full state at a given event. This was previously used particularly
@@ -933,7 +916,6 @@ async def update_membership_locked(
933916
)
934917
# InviteRule.IGNORE is handled at the sync layer.
935918

936-
# An empty prev_events list is allowed as long as the auth_event_ids are present
937919
if prev_event_ids is not None:
938920
return await self._local_membership_update(
939921
requester=requester,
@@ -942,7 +924,6 @@ async def update_membership_locked(
942924
membership=effective_membership_state,
943925
txn_id=txn_id,
944926
ratelimit=ratelimit,
945-
allow_no_prev_events=allow_no_prev_events,
946927
prev_event_ids=prev_event_ids,
947928
state_event_ids=state_event_ids,
948929
depth=depth,

tests/handlers/test_message.py

Lines changed: 5 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -204,46 +204,19 @@ def test_duplicated_txn_id_one_call(self) -> None:
204204
self.assertEqual(len(events), 2)
205205
self.assertEqual(events[0].event_id, events[1].event_id)
206206

207-
def test_when_empty_prev_events_allowed_create_event_with_empty_prev_events(
207+
def test_reject_event_with_empty_prev_events(
208208
self,
209209
) -> None:
210-
"""When we set allow_no_prev_events=True, should be able to create a
211-
event without any prev_events (only auth_events).
212210
"""
213-
# Create a member event we can use as an auth_event
214-
memberEvent, _ = self._create_and_persist_member_event()
215-
216-
# Try to create the event with empty prev_events bit with some auth_events
217-
event, _ = self.get_success(
218-
self.handler.create_event(
219-
self.requester,
220-
{
221-
"type": EventTypes.Message,
222-
"room_id": self.room_id,
223-
"sender": self.requester.user.to_string(),
224-
"content": {"msgtype": "m.text", "body": random_string(5)},
225-
},
226-
# Empty prev_events is the key thing we're testing here
227-
prev_event_ids=[],
228-
# But with some auth_events
229-
auth_event_ids=[memberEvent.event_id],
230-
# Allow no prev_events!
231-
allow_no_prev_events=True,
232-
)
233-
)
234-
self.assertIsNotNone(event)
235-
236-
def test_when_empty_prev_events_not_allowed_reject_event_with_empty_prev_events(
237-
self,
238-
) -> None:
239-
"""When we set allow_no_prev_events=False, shouldn't be able to create a
240-
event without any prev_events even if it has auth_events. Expect an
241-
exception to be raised.
211+
Shouldn't be able to create an event without any `prev_events` even if it has
212+
`auth_events`. Expect an exception to be raised.
242213
"""
243214
# Create a member event we can use as an auth_event
244215
memberEvent, _ = self._create_and_persist_member_event()
245216

246217
# Try to create the event with empty prev_events but with some auth_events
218+
#
219+
# We expect the test to fail because empty prev_events are not allowed
247220
self.get_failure(
248221
self.handler.create_event(
249222
self.requester,
@@ -257,35 +230,6 @@ def test_when_empty_prev_events_not_allowed_reject_event_with_empty_prev_events(
257230
prev_event_ids=[],
258231
# But with some auth_events
259232
auth_event_ids=[memberEvent.event_id],
260-
# We expect the test to fail because empty prev_events are not
261-
# allowed here!
262-
allow_no_prev_events=False,
263-
),
264-
AssertionError,
265-
)
266-
267-
def test_when_empty_prev_events_allowed_reject_event_with_empty_prev_events_and_auth_events(
268-
self,
269-
) -> None:
270-
"""When we set allow_no_prev_events=True, should be able to create a
271-
event without any prev_events or auth_events. Expect an exception to be
272-
raised.
273-
"""
274-
# Try to create the event with empty prev_events and empty auth_events
275-
self.get_failure(
276-
self.handler.create_event(
277-
self.requester,
278-
{
279-
"type": EventTypes.Message,
280-
"room_id": self.room_id,
281-
"sender": self.requester.user.to_string(),
282-
"content": {"msgtype": "m.text", "body": random_string(5)},
283-
},
284-
prev_event_ids=[],
285-
# The event should be rejected when there are no auth_events
286-
auth_event_ids=[],
287-
# Allow no prev_events!
288-
allow_no_prev_events=True,
289233
),
290234
AssertionError,
291235
)

0 commit comments

Comments
 (0)