Skip to content

Make serializers.ValidationError compatible with Django ValidationError #8077

@dgasparri

Description

@dgasparri

Django Rest Framework ValidationError in rest_framework.exceptions has the following constructor:

def __init__(self, detail=None, code=None)

Django original ValidationError in django.core.exceptions has the following constructor:

def __init__(self, message, code=None, params=None)

The difference is subtle and obscure, especially for a beginner that read the Django documentation on how to properly write a ValidationError exception https://docs.djangoproject.com/en/3.2/ref/forms/validation/#raising-validationerror
. I spent an hour trying to figure out why Django "proper way" of writing a validation exception was not working for me

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions