diff --git a/changelog.d/12770.bugfix b/changelog.d/12770.bugfix
new file mode 100644
index 0000000000..a958f9a16b
--- /dev/null
+++ b/changelog.d/12770.bugfix
@@ -0,0 +1 @@
+Delete events from the `federation_inbound_events_staging` table when a room is purged through the admin API.
diff --git a/synapse/storage/databases/main/purge_events.py b/synapse/storage/databases/main/purge_events.py
index 38ba91af4c..c94d5f9f81 100644
--- a/synapse/storage/databases/main/purge_events.py
+++ b/synapse/storage/databases/main/purge_events.py
@@ -417,6 +417,7 @@ class PurgeEventsStore(StateGroupWorkerStore, CacheInvalidationWorkerStore):
"room_account_data",
"room_tags",
"local_current_membership",
+ "federation_inbound_events_staging",
):
logger.info("[purge] removing %s from %s", room_id, table)
txn.execute("DELETE FROM %s WHERE room_id=?" % (table,), (room_id,))
diff --git a/tests/rest/admin/test_room.py b/tests/rest/admin/test_room.py
index 95282f078e..608d3f2dc3 100644
--- a/tests/rest/admin/test_room.py
+++ b/tests/rest/admin/test_room.py
@@ -2489,4 +2489,5 @@ PURGE_TABLES = [
"room_tags",
# "state_groups", # Current impl leaves orphaned state groups around.
"state_groups_state",
+ "federation_inbound_events_staging",
]
|