From 7f33826d1d70d6bed1ef94a7afc0a13e84770edd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sybren=20A=2E=20St=C3=BCvel?= Date: Fri, 5 Jan 2018 14:41:59 +0100 Subject: [PATCH] prepare_user_data: Always return a dict --- pillar/celery/search_index_tasks.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/pillar/celery/search_index_tasks.py b/pillar/celery/search_index_tasks.py index 2c09c61a..e88ba15a 100644 --- a/pillar/celery/search_index_tasks.py +++ b/pillar/celery/search_index_tasks.py @@ -114,7 +114,9 @@ def prepare_node_data(node_id: str, node: dict=None) -> dict: def prepare_user_data(user_id: str, user=None) -> dict: """ - Prepare data to index for user node + Prepare data to index for user node. + + Returns an empty dict if the user should not be indexed. """ if not user: @@ -124,13 +126,13 @@ def prepare_user_data(user_id: str, user=None) -> dict: user = users_coll.find_one({'_id': user_oid}) if user is None: - log.warning('Unable to find user %s, not updating Algolia.', user_oid) - return + log.warning('Unable to find user %s, not updating Algolia.', user_id) + return {} user_roles = set(user.get('roles', ())) if 'service' in user_roles: - return + return {} # Strip unneeded roles index_roles = user_roles.intersection(current_app.user_roles_indexable)