From 678adcb697e5cf21c5230135b45f02f1ff62a4c7 Mon Sep 17 00:00:00 2001 From: Goffi Date: Sun, 19 Apr 2020 16:38:46 +0200 Subject: [PATCH] plugin identity: fixed update with `get_all` + better new data detection for avatar: - when metadata doesn't exist, update with `get_all` set doesn't crash anymore. - fixed avatarUpdateIsNewData --- sat/plugins/plugin_misc_identity.py | 31 +++++++++++------------------ 1 file changed, 12 insertions(+), 19 deletions(-) diff --git a/sat/plugins/plugin_misc_identity.py b/sat/plugins/plugin_misc_identity.py index 01ef7692..c88d7796 100644 --- a/sat/plugins/plugin_misc_identity.py +++ b/sat/plugins/plugin_misc_identity.py @@ -355,15 +355,16 @@ class Identity: except KeyError: update_is_new_data = self.defaultUpdateIsNewData - if not update_is_new_data(client, entity, cached_data, data): + if data is None: if cached_data is None: log.debug( f"{metadata_name} for {entity} is already disabled, nothing to " f"do") - else: - log.debug( - f"{metadata_name} for {entity} is already in cache, nothing to " - f"do") + return + elif not update_is_new_data(client, entity, cached_data, data): + log.debug( + f"{metadata_name} for {entity} is already in cache, nothing to " + f"do") return # we can't use the cache, so we do the update @@ -373,7 +374,10 @@ class Identity: if metadata.get('get_all', False): # get_all is set, meaning that we have to check all plugins # so we first delete current cache - self.host.memory.delEntityDatum(client, entity, metadata_name) + try: + self.host.memory.delEntityDatum(client, entity, metadata_name) + except KeyError: + pass # then fill it again by calling get, which will retrieve all values await self.get(client, metadata_name, entity) return @@ -452,19 +456,8 @@ class Identity: "cache_uid": cache_uid, } - def avatarUpdateIsNewData(self, client, entity, cached_data, file_path): - if cached_data is None: - return file_path is not None - - if file_path is not None and file_path == cached_data['path']: - if file_path is None: - log.debug( - f"Avatar is already disabled for {entity}, nothing to do") - else: - log.debug( - f"Avatar at {file_path} is already used by {entity}, nothing " - f"to do") - return + def avatarUpdateIsNewData(self, client, entity, cached_data, new_data): + return new_data['path'] != cached_data['path'] async def avatarUpdateDataFilter(self, client, entity, data): if not isinstance(data, dict):