From 9c9dac6ad85d83213fb8b7536d1faf9106e11080 Mon Sep 17 00:00:00 2001 From: David Lechner Date: Thu, 3 Nov 2022 10:40:00 -0500 Subject: [PATCH] bluezdbus/manager: ignore KeyError when properties removed Apparently, BlueZ will sometimes request to remove properties that were not set in the first place. Fixes: #1107 --- CHANGELOG.rst | 1 + bleak/backends/bluezdbus/manager.py | 7 ++++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index d36919f2..8d8b3202 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -14,6 +14,7 @@ Fixed ------ * Fixed crash when getting services in WinRT backend. * Fixed cache mode when retrying get services in WinRT backend. +* Fixed ``KeyError`` crash in BlueZ backend when removing non-existent property. Fixes #1107. `0.19.1`_ (2022-10-29) ====================== diff --git a/bleak/backends/bluezdbus/manager.py b/bleak/backends/bluezdbus/manager.py index 0ccf6f39..8ee6e5d0 100644 --- a/bleak/backends/bluezdbus/manager.py +++ b/bleak/backends/bluezdbus/manager.py @@ -818,7 +818,12 @@ def _parse_msg(self, message: Message): self_interface.update(unpack_variants(changed)) for name in invalidated: - del self_interface[name] + try: + del self_interface[name] + except KeyError: + # sometimes there BlueZ tries to remove properties + # that were never added + pass # then call any callbacks so they will be called with the # updated state