From e0a6c4b5bd1cc0393ff404fd849d9ffa9ce7da1c Mon Sep 17 00:00:00 2001 From: Ryan P Kilby Date: Mon, 2 Oct 2017 08:51:48 -0400 Subject: [PATCH] Clarify 'to_internal_value()' validation behavior (#5466) --- docs/api-guide/serializers.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/api-guide/serializers.md b/docs/api-guide/serializers.md index e95f2849b..515e7cad8 100644 --- a/docs/api-guide/serializers.md +++ b/docs/api-guide/serializers.md @@ -993,7 +993,7 @@ The following class is an example of a generic serializer that can handle coerci ## Overriding serialization and deserialization behavior -If you need to alter the serialization, deserialization or validation of a serializer class you can do so by overriding the `.to_representation()` or `.to_internal_value()` methods. +If you need to alter the serialization or deserialization behavior of a serializer class, you can do so by overriding the `.to_representation()` or `.to_internal_value()` methods. Some reasons this might be useful include... @@ -1011,7 +1011,7 @@ Takes the object instance that requires serialization, and should return a primi Takes the unvalidated incoming data as input and should return the validated data that will be made available as `serializer.validated_data`. The return value will also be passed to the `.create()` or `.update()` methods if `.save()` is called on the serializer class. -If any of the validation fails, then the method should raise a `serializers.ValidationError(errors)`. Typically the `errors` argument here will be a dictionary mapping field names to error messages. +If any of the validation fails, then the method should raise a `serializers.ValidationError(errors)`. The `errors` argument should be a dictionary mapping field names (or `settings.NON_FIELD_ERRORS_KEY`) to a list of error messages. If you don't need to alter deserialization behavior and instead want to provide object-level validation, it's recommended that you intead override the [`.validate()`](#object-level-validation) method. The `data` argument passed to this method will normally be the value of `request.data`, so the datatype it provides will depend on the parser classes you have configured for your API. @@ -1155,7 +1155,7 @@ The [html-json-forms][html-json-forms] package provides an algorithm and seriali ## QueryFields -[djangorestframework-queryfields][djangorestframework-queryfields] allows API clients to specify which fields will be sent in the response via inclusion/exclusion query parameters. +[djangorestframework-queryfields][djangorestframework-queryfields] allows API clients to specify which fields will be sent in the response via inclusion/exclusion query parameters. ## DRF Writable Nested