Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
giuseppenovielli opened this issue Mar 9, 2024 · 0 comments
Labels
help wanted Extra attention is needed

Comments

@giuseppenovielli
Copy link
Owner

giuseppenovielli commented Mar 9, 2024

Start Django Rest Framework 3.0 announcement Model.full_clean() is not called before save instance into db.

This policy moves validation business logic from models to views and break DRY purpose.

encode/django-rest-framework#7850 (comment)

Workaround
ValidateModelSerializer
NestedValidateModelSerializer

SPECS
It enable developers to run model.full_clean(), when serializers.is_valid() is called.
It also have limited support to nested writable serializer. Developers can pass into **kwargs parameters, other foreignKey not yet saved into db.

It is a valid compromise to help DRY purpose?

@giuseppenovielli giuseppenovielli added the help wanted Extra attention is needed label Mar 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

1 participant