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

Fix insert of duplicate key into event_json #10719

Closed
Closed
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/10719.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix instert failure because of duplicate key when an incoming event id is present in the table event_json but not in events.
22 changes: 11 additions & 11 deletions synapse/storage/databases/main/events.py
Original file line number Diff line number Diff line change
Expand Up @@ -1334,19 +1334,19 @@ def get_internal_metadata(event):

return im

self.db_pool.simple_insert_many_txn(
self.db_pool.simple_upsert_many_txn(
txn,
table="event_json",
values=[
{
"event_id": event.event_id,
"room_id": event.room_id,
"internal_metadata": json_encoder.encode(
get_internal_metadata(event)
),
"json": json_encoder.encode(event_dict(event)),
"format_version": event.format_version,
}
key_names=["event_id"],
key_values=[[event.event_id] for event, _ in events_and_contexts],
value_names=["room_id", "internal_metadata", "json", "format_version"],
value_values=[
[
event.room_id,
json_encoder.encode(get_internal_metadata(event)),
json_encoder.encode(event_dict(event)),
event.format_version,
]
for event, _ in events_and_contexts
],
)
Expand Down