From 0b2948ccb78b553a4c5a2b284465cff8208f233e Mon Sep 17 00:00:00 2001 From: mandala21 Date: Tue, 23 Apr 2019 19:16:18 -0300 Subject: [PATCH] resolve #6555 add status_code in constructor of ValidationError --- rest_framework/exceptions.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/rest_framework/exceptions.py b/rest_framework/exceptions.py index f79b16129..1a22879e1 100644 --- a/rest_framework/exceptions.py +++ b/rest_framework/exceptions.py @@ -144,11 +144,13 @@ class ValidationError(APIException): default_detail = _('Invalid input.') default_code = 'invalid' - def __init__(self, detail=None, code=None): + def __init__(self, detail=None, code=None, status_code=None): if detail is None: detail = self.default_detail if code is None: code = self.default_code + if status_code: + self.status_code = status_code # For validation failures, we may collect many errors together, # so the details should always be coerced to a list if not already.