From 0b8aff1054a48646fabd43a013b942f87b8f58ee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sybren=20A=2E=20St=C3=BCvel?= Date: Fri, 8 Jul 2016 12:08:52 +0200 Subject: [PATCH] sync_project_groups: gracefully handle invalid object IDs. Otherwise a mistake at the CLI will create a bugsnag. --- pillar/manage.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/pillar/manage.py b/pillar/manage.py index ccaaf2f3..794081c1 100755 --- a/pillar/manage.py +++ b/pillar/manage.py @@ -7,7 +7,7 @@ import copy import os import logging -from bson.objectid import ObjectId +from bson.objectid import ObjectId, InvalidId from eve.methods.put import put_internal from eve.methods.post import post_internal from flask.ext.script import Manager @@ -983,7 +983,11 @@ def sync_project_groups(user_email, fix): if '@' in user_email: where = {'email': user_email} else: - where = {'_id': ObjectId(user_email)} + try: + where = {'_id': ObjectId(user_email)} + except InvalidId: + log.warning('Invalid ObjectID: %s', user_email) + return user = users_coll.find_one(where, projection={'_id': 1, 'groups': 1}) if user is None: