In commit 5392be4ddb, there was a change
made when cleaning up the template for the API listing that caused 2
spaces to appear before every header item (except the first) and before
the first line of the body of the response. This meant that it often
looked like:
HTTP 200 OK
Allow: GET, OPTIONS
Content-Type: application/json
Vary: Accept
{
"key": "value",
"key2": "value2"
}
This change removes those leading spaces, so that it will now look like:
HTTP 200 OK
Allow: GET, OPTIONS
Content-Type: application/json
Vary: Accept
{
"key": "value",
"key2": "value2"
}
`ValidationErrorMessage` is a string-like object that holds a code
attribute.
The code attribute has been removed from ValidationError to be able
to maintain better backward compatibility.
`ValidationErrorMessage` is abstracted in `ValidationError`'s
constructor
This patch is meant to fix#3111, regarding comments made to #3137
and #3169.
The `ValidationError` will now contain a `code` attribute.
Before this patch, `ValidationError.detail` only contained a
`dict` with values equal to a `list` of string error messages or
directly a `list` containing string error messages.
Now, the string error messages are replaced with `ValidationError`.
This means that, depending on the case, you will not only get a
string back but a all object containing both the error message and
the error code, respectively `ValidationError.detail` and
`ValidationError.code`.
It is important to note that the `code` attribute is not relevant
when the `ValidationError` represents a combination of errors and
hence is `None` in such cases.
The main benefit of this change is that the error message and
error code are now accessible the custom exception handler and can
be used to format the error response.
An custom exception handler example is available in the
`TestValidationErrorWithCode` test.
We keep `Serializer.errors`'s return type unchanged in
order to maintain backward compatibility.
The error codes will only be propagated to the `exception_handler`
or accessible through the `Serializer._errors` private attribute.