From 85b6ff2d7fbde59664b36acf8b4517b2e3c7b70f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sybren=20A=2E=20St=C3=BCvel?= Date: Wed, 24 May 2017 16:31:15 +0200 Subject: [PATCH] Use str2id(x) instead of ObjectId(x) The latter produces an internal server error if 'x' is not a valid ObjectId, whereas the fromer produces a 400 Bad Request. --- pillar/api/projects/routes.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/pillar/api/projects/routes.py b/pillar/api/projects/routes.py index f312059d..a4e7181a 100644 --- a/pillar/api/projects/routes.py +++ b/pillar/api/projects/routes.py @@ -41,6 +41,8 @@ def project_manage_users(): No changes are done on the project itself. """ + from pillar.api.utils import str2id + projects_collection = current_app.data.driver.db['projects'] users_collection = current_app.data.driver.db['users'] @@ -57,8 +59,8 @@ def project_manage_users(): # The request is not a form, since it comes from the API sdk data = json.loads(request.data) - project_id = ObjectId(data['project_id']) - target_user_id = ObjectId(data['user_id']) + project_id = str2id(data['project_id']) + target_user_id = str2id(data['user_id']) action = data['action'] current_user_id = g.current_user['user_id']