This repository was archived by the owner on Apr 26, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
This repository was archived by the owner on Apr 26, 2024. It is now read-only.
DELETE /directory/rooms/ALIAS doesn't handle the case of a nonexistant alias #11319
Copy link
Copy link
Closed
Description
Spec says we should return 404.
AFAICS we only return 200 (or maybe 500 if there's an internal server error).
synapse/synapse/rest/client/directory.py
Lines 94 to 124 in 2af6d31
async def on_DELETE( | |
self, request: SynapseRequest, room_alias: str | |
) -> Tuple[int, JsonDict]: | |
room_alias_obj = RoomAlias.from_string(room_alias) | |
try: | |
service = self.auth.get_appservice_by_req(request) | |
await self.directory_handler.delete_appservice_association( | |
service, room_alias_obj | |
) | |
logger.info( | |
"Application service at %s deleted alias %s", | |
service.url, | |
room_alias_obj.to_string(), | |
) | |
return 200, {} | |
except InvalidClientCredentialsError: | |
# fallback to default user behaviour if they aren't an AS | |
pass | |
requester = await self.auth.get_user_by_req(request) | |
user = requester.user | |
await self.directory_handler.delete_association(requester, room_alias_obj) | |
logger.info( | |
"User %s deleted alias %s", user.to_string(), room_alias_obj.to_string() | |
) | |
return 200, {} |
Discovered because mypy spotted the return type hint here was wrong (we may return None
):
synapse/synapse/storage/databases/main/directory.py
Lines 136 to 159 in 40a1fdd
def _delete_room_alias_txn(self, txn, room_alias: RoomAlias) -> str: | |
txn.execute( | |
"SELECT room_id FROM room_aliases WHERE room_alias = ?", | |
(room_alias.to_string(),), | |
) | |
res = txn.fetchone() | |
if res: | |
room_id = res[0] | |
else: | |
return None | |
txn.execute( | |
"DELETE FROM room_aliases WHERE room_alias = ?", (room_alias.to_string(),) | |
) | |
txn.execute( | |
"DELETE FROM room_alias_servers WHERE room_alias = ?", | |
(room_alias.to_string(),), | |
) | |
self._invalidate_cache_and_stream(txn, self.get_aliases_for_room, (room_id,)) | |
return room_id |
Metadata
Metadata
Assignees
Labels
No labels