diff --git a/sat_frontends/quick_frontend/quick_widgets.py b/sat_frontends/quick_frontend/quick_widgets.py index 81ca9f61..8c0e70e9 100644 --- a/sat_frontends/quick_frontend/quick_widgets.py +++ b/sat_frontends/quick_frontend/quick_widgets.py @@ -255,6 +255,10 @@ class QuickWidgetsManager(object): if widget is None: raise exceptions.InternalError( "on_existing_widget method must return the widget to use") + if widget not in widgets_map[hash_]: + log.debug( + "the widget returned by on_existing_widget is new, adding it") + widgets_map[hash_].append(widget) else: raise exceptions.InternalError( "Unexpected on_existing_widget value ({})".format(on_existing_widget)) @@ -299,7 +303,11 @@ class QuickWidgetsManager(object): return widget_hash = str(class_.getWidgetHash(widget_to_delete.target, widget_to_delete.profiles)) - widget_instances = widgets_map[widget_hash] + try: + widget_instances = widgets_map[widget_hash] + except KeyError: + log.error(f"no instance of {class_.__name__} found with hash {widget_hash!r}") + return if all_instances: widget_instances.clear() else: @@ -315,7 +323,7 @@ class QuickWidgetsManager(object): # all instances with this hash have been deleted # we remove the hash itself del widgets_map[widget_hash] - log.debug("All instances of {cls} with hash {widget_hash} have been deleted" + log.debug("All instances of {cls} with hash {widget_hash!r} have been deleted" .format(cls=class_, widget_hash=widget_hash))