From bfce663a604bf9d2c891ab2414fee0e59cabeb46 Mon Sep 17 00:00:00 2001 From: totycro Date: Mon, 9 Jan 2023 19:53:49 +0100 Subject: [PATCH] Update documentation regarding arguments of ValidationError (#8807) The documentation used to state that the `detail` argument was mandatory, but in fact it currently is not. --- docs/api-guide/exceptions.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/docs/api-guide/exceptions.md b/docs/api-guide/exceptions.md index 347541d56..3f641fac2 100644 --- a/docs/api-guide/exceptions.md +++ b/docs/api-guide/exceptions.md @@ -217,11 +217,10 @@ By default this exception results in a response with the HTTP status code "429 T ## ValidationError -**Signature:** `ValidationError(detail, code=None)` +**Signature:** `ValidationError(detail=None, code=None)` The `ValidationError` exception is slightly different from the other `APIException` classes: -* The `detail` argument is mandatory, not optional. * The `detail` argument may be a list or dictionary of error details, and may also be a nested data structure. By using a dictionary, you can specify field-level errors while performing object-level validation in the `validate()` method of a serializer. For example. `raise serializers.ValidationError({'name': 'Please enter a valid name.'})` * By convention you should import the serializers module and use a fully qualified `ValidationError` style, in order to differentiate it from Django's built-in validation error. For example. `raise serializers.ValidationError('This field must be an integer value.')`