Skip to content
This repository was archived by the owner on Apr 26, 2024. It is now read-only.
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

@DMRobertson

Description

@DMRobertson

Spec says we should return 404.

AFAICS we only return 200 (or maybe 500 if there's an internal server error).

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):

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

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions