From 7de53ea24aed3edbc33c04578f728e3faeb02401 Mon Sep 17 00:00:00 2001 From: adrian-turjak Date: Fri, 12 May 2017 15:57:00 +1200 Subject: [PATCH] Fixing two bugs related to approval * If roles not present in keystone, we throw and error while trying to handle an error. * when data is empty we fail to return a useful error message. Change-Id: I8572cf7ce35997cd7b5a38658a3e4eb26afe4941 --- stacktask/actions/v1/base.py | 2 +- stacktask/api/v1/views.py | 8 +++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/stacktask/actions/v1/base.py b/stacktask/actions/v1/base.py index 1d313d4..26543bc 100644 --- a/stacktask/actions/v1/base.py +++ b/stacktask/actions/v1/base.py @@ -289,7 +289,7 @@ class UserMixin(ResourceMixin): except Exception as e: self.add_note( "Error: '%s' while %s the roles: %s on user: %s " % - (e, action_string, self.roles, user)) + (e, action_string, roles, user)) raise def enable_user(self, user=None): diff --git a/stacktask/api/v1/views.py b/stacktask/api/v1/views.py index 53c2676..cbfc566 100644 --- a/stacktask/api/v1/views.py +++ b/stacktask/api/v1/views.py @@ -18,6 +18,7 @@ from django.conf import settings from django.utils import timezone from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger +from rest_framework.exceptions import ParseError from rest_framework.response import Response from rest_framework.views import APIView @@ -350,7 +351,12 @@ class TaskDetail(APIViewWithLogger): {'errors': ['No task with this id.']}, status=404) - if request.data.get('approved') is not True: + try: + if request.data.get('approved') is not True: + return Response( + {'approved': ["this is a required boolean field."]}, + status=400) + except ParseError: return Response( {'approved': ["this is a required boolean field."]}, status=400)