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

Do not bundle aggregations for APIs which shouldn't include them. #11592

Merged
merged 4 commits into from
Dec 20, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/11592.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix a long-standing bug where responses included bundled aggregations when they should not, per [MSC2675](https://github.com/matrix-org/matrix-doc/pull/2675).
2 changes: 1 addition & 1 deletion synapse/events/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,7 @@ async def serialize_event(
event: Union[JsonDict, EventBase],
time_now: int,
*,
bundle_aggregations: bool = True,
bundle_aggregations: bool = False,
**kwargs: Any,
) -> JsonDict:
"""Serializes a single event.
Expand Down
2 changes: 0 additions & 2 deletions synapse/handlers/events.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,6 @@ async def get_stream(
events,
time_now,
as_client_event=as_client_event,
# Don't bundle aggregations as this is a deprecated API.
bundle_aggregations=False,
)

chunk = {
Expand Down
18 changes: 4 additions & 14 deletions synapse/handlers/initial_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,8 +173,6 @@ async def handle_room(event: RoomsForUser) -> None:
d["invite"] = await self._event_serializer.serialize_event(
invite_event,
time_now,
# Don't bundle aggregations as this is a deprecated API.
bundle_aggregations=False,
as_client_event=as_client_event,
)

Expand Down Expand Up @@ -227,8 +225,6 @@ async def handle_room(event: RoomsForUser) -> None:
await self._event_serializer.serialize_events(
messages,
time_now=time_now,
# Don't bundle aggregations as this is a deprecated API.
bundle_aggregations=False,
as_client_event=as_client_event,
)
),
Expand All @@ -239,8 +235,6 @@ async def handle_room(event: RoomsForUser) -> None:
d["state"] = await self._event_serializer.serialize_events(
current_state.values(),
time_now=time_now,
# Don't bundle aggregations as this is a deprecated API.
bundle_aggregations=False,
as_client_event=as_client_event,
)

Expand Down Expand Up @@ -382,17 +376,15 @@ async def _room_initial_sync_parted(
"messages": {
"chunk": (
# Don't bundle aggregations as this is a deprecated API.
await self._event_serializer.serialize_events(
messages, time_now, bundle_aggregations=False
)
await self._event_serializer.serialize_events(messages, time_now)
),
"start": await start_token.to_string(self.store),
"end": await end_token.to_string(self.store),
},
"state": (
# Don't bundle aggregations as this is a deprecated API.
await self._event_serializer.serialize_events(
room_state.values(), time_now, bundle_aggregations=False
room_state.values(), time_now
)
),
"presence": [],
Expand All @@ -413,7 +405,7 @@ async def _room_initial_sync_joined(
time_now = self.clock.time_msec()
# Don't bundle aggregations as this is a deprecated API.
state = await self._event_serializer.serialize_events(
current_state.values(), time_now, bundle_aggregations=False
current_state.values(), time_now
)

now_token = self.hs.get_event_sources().get_current_token()
Expand Down Expand Up @@ -488,9 +480,7 @@ async def get_receipts() -> List[JsonDict]:
"messages": {
"chunk": (
# Don't bundle aggregations as this is a deprecated API.
await self._event_serializer.serialize_events(
messages, time_now, bundle_aggregations=False
)
await self._event_serializer.serialize_events(messages, time_now)
),
"start": await start_token.to_string(self.store),
"end": await end_token.to_string(self.store),
Expand Down
4 changes: 3 additions & 1 deletion synapse/handlers/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,9 @@ async def get_state_events(
room_state = room_state_events[membership_event_id]

now = self.clock.time_msec()
events = await self._event_serializer.serialize_events(room_state.values(), now)
events = await self._event_serializer.serialize_events(
room_state.values(), now, bundle_aggregations=True
)
return events

async def get_joined_members(self, requester: Requester, room_id: str) -> dict:
Expand Down
5 changes: 4 additions & 1 deletion synapse/handlers/pagination.py
Original file line number Diff line number Diff line change
Expand Up @@ -542,7 +542,10 @@ async def get_messages(
chunk = {
"chunk": (
await self._event_serializer.serialize_events(
events, time_now, as_client_event=as_client_event
events,
time_now,
bundle_aggregations=True,
as_client_event=as_client_event,
)
),
"start": await from_token.to_string(self.store),
Expand Down
12 changes: 9 additions & 3 deletions synapse/rest/admin/rooms.py
Original file line number Diff line number Diff line change
Expand Up @@ -745,13 +745,19 @@ async def on_GET(

time_now = self.clock.time_msec()
results["events_before"] = await self._event_serializer.serialize_events(
results["events_before"], time_now
results["events_before"],
time_now,
bundle_aggregations=True,
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As these are admin APIs we can do whatever we want, but the intention is for them to match the Client-Server APIs, so I gave them the same behavior!

)
results["event"] = await self._event_serializer.serialize_event(
results["event"], time_now
results["event"],
time_now,
bundle_aggregations=True,
)
results["events_after"] = await self._event_serializer.serialize_events(
results["events_after"], time_now
results["events_after"],
time_now,
bundle_aggregations=True,
)
results["state"] = await self._event_serializer.serialize_events(
results["state"], time_now
Expand Down
4 changes: 3 additions & 1 deletion synapse/rest/client/relations.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,9 @@ async def on_GET(
)
# The relations returned for the requested event do include their
# bundled aggregations.
serialized_events = await self._event_serializer.serialize_events(events, now)
serialized_events = await self._event_serializer.serialize_events(
events, now, bundle_aggregations=True
)

return_value = pagination_chunk.to_dict()
return_value["chunk"] = serialized_events
Expand Down
10 changes: 6 additions & 4 deletions synapse/rest/client/room.py
Original file line number Diff line number Diff line change
Expand Up @@ -662,7 +662,9 @@ async def on_GET(

time_now = self.clock.time_msec()
if event:
event_dict = await self._event_serializer.serialize_event(event, time_now)
event_dict = await self._event_serializer.serialize_event(
event, time_now, bundle_aggregations=True
)
return 200, event_dict

raise SynapseError(404, "Event not found.", errcode=Codes.NOT_FOUND)
Expand Down Expand Up @@ -707,13 +709,13 @@ async def on_GET(

time_now = self.clock.time_msec()
results["events_before"] = await self._event_serializer.serialize_events(
results["events_before"], time_now
results["events_before"], time_now, bundle_aggregations=True
)
results["event"] = await self._event_serializer.serialize_event(
results["event"], time_now
results["event"], time_now, bundle_aggregations=True
)
results["events_after"] = await self._event_serializer.serialize_events(
results["events_after"], time_now
results["events_after"], time_now, bundle_aggregations=True
)
results["state"] = await self._event_serializer.serialize_events(
results["state"], time_now
Expand Down