Skip to content

DRF wrongly moves validation business logic from models to views #3144

@grjones

Description

@grjones

I realize this was an intentional change in 3.0 where ModelSerializers no longer run model-level clean or full_clean, however I am submitting this as a bug because to me and others it is a violation of business logic residing in views instead of models. It's ok of course to close this out immediately, but I hope this behavior will be reconsidered one day. Here are some questions I would like us to think about:

  • If validations happen in the serializers (at the view-level), how do I ensure the same validations occur at the model level if for example I am running one off scripts that have nothing to do with views or http? Do I have to implement that logic twice?
  • Is there an expectation by developers that if you have implemented custom validations at the model level that these will be run by serializers, especially since ModelForm does?
  • What happens in the case where in your models you are forcing a full_clean (perhaps by including it in the save method)? Will serializers know how to handle an exception from an explicit full_clean?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions