From 322aa4847fa10e0cd99db1043e89338a2dc325a3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Marczykowski-G=C3=B3recki?= Date: Wed, 10 Dec 2025 00:35:07 +0100 Subject: [PATCH] Deserialize device in events only if there is a handler registered Deserializing device parameter may trigger a call to get remaining details. Don't do that if there are no handlers for such event anyway. Specifically, this avoids calling admin.vm.device.usb.Available (and others) by sys-audio whenever new device is plugged in. --- qubesadmin/events/__init__.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/qubesadmin/events/__init__.py b/qubesadmin/events/__init__.py index f6c35ed7..ce2d832a 100644 --- a/qubesadmin/events/__init__.py +++ b/qubesadmin/events/__init__.py @@ -264,6 +264,15 @@ def handle(self, subject, event, **kwargs): except KeyError: pass + handlers = [h_func for h_name, h_func_set in self.handlers.items() + for h_func in h_func_set + if fnmatch.fnmatch(event, h_name)] + + # skip deserializing parameters (which may make further Admin API calls) + # if no handler is registered for the event + if not handlers: + return + # deserialize known attributes if event.startswith('device-'): try: @@ -292,9 +301,6 @@ def handle(self, subject, event, **kwargs): except (KeyError, ValueError): pass - handlers = [h_func for h_name, h_func_set in self.handlers.items() - for h_func in h_func_set - if fnmatch.fnmatch(event, h_name)] for handler in handlers: try: handler(subject, event, **kwargs)