diff frontends/src/quick_frontend/quick_contact_list.py @ 2082:e8cb9cc09485

quick frontend(contact_list): avoid crash when resource in cache has not priority
author Goffi <goffi@goffi.org>
date Sun, 02 Oct 2016 13:46:29 +0200
parents f3167c873e7b
children 4d9aeae5d9d0
line wrap: on
line diff
--- a/frontends/src/quick_frontend/quick_contact_list.py	Sun Sep 25 19:18:45 2016 +0200
+++ b/frontends/src/quick_frontend/quick_contact_list.py	Sun Oct 02 13:46:29 2016 +0200
@@ -501,7 +501,9 @@
             resource_data[C.PRESENCE_STATUSES] = statuses
 
             if entity.bare not in self._specials:
-                priority_resource = max(resources_data, key=lambda res: resources_data[res][C.PRESENCE_PRIORITY])
+                # we may have resources with no priority
+                # (when a cached value is added for a not connected resource)
+                priority_resource = max(resources_data, key=lambda res: resources_data[res].get(C.PRESENCE_PRIORITY, -2**32))
                 cache[C.CONTACT_MAIN_RESOURCE] = priority_resource
         self.update([entity], C.UPDATE_MODIFY, self.profile)