diff options
author | reivilibre <oliverw@matrix.org> | 2021-12-13 15:39:43 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-12-13 15:39:43 +0000 |
commit | e5cdb9e2339e321e8a77a898d362d7fbc476303b (patch) | |
tree | 7ddb175af84267fd6e1cfb547346a7358a214fb5 /synapse/storage/databases/main | |
parent | Allow events to be created with no `prev_events` (MSC2716) (#11243) (diff) | |
download | synapse-e5cdb9e2339e321e8a77a898d362d7fbc476303b.tar.xz |
Make `get_device` return None if the device doesn't exist rather than raising an exception. (#11565)
Co-authored-by: Sean Quah <8349537+squahtx@users.noreply.github.com>
Diffstat (limited to 'synapse/storage/databases/main')
-rw-r--r-- | synapse/storage/databases/main/devices.py | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/synapse/storage/databases/main/devices.py b/synapse/storage/databases/main/devices.py index 838a2a6a3d..eff825dd22 100644 --- a/synapse/storage/databases/main/devices.py +++ b/synapse/storage/databases/main/devices.py @@ -101,7 +101,9 @@ class DeviceWorkerStore(SQLBaseStore): "count_devices_by_users", count_devices_by_users_txn, user_ids ) - async def get_device(self, user_id: str, device_id: str) -> Dict[str, Any]: + async def get_device( + self, user_id: str, device_id: str + ) -> Optional[Dict[str, Any]]: """Retrieve a device. Only returns devices that are not marked as hidden. @@ -109,15 +111,15 @@ class DeviceWorkerStore(SQLBaseStore): user_id: The ID of the user which owns the device device_id: The ID of the device to retrieve Returns: - A dict containing the device information - Raises: - StoreError: if the device is not found + A dict containing the device information, or `None` if the device does not + exist. """ return await self.db_pool.simple_select_one( table="devices", keyvalues={"user_id": user_id, "device_id": device_id, "hidden": False}, retcols=("user_id", "device_id", "display_name"), desc="get_device", + allow_none=True, ) async def get_devices_by_user(self, user_id: str) -> Dict[str, Dict[str, str]]: |