#34061 closed New feature (wontfix)

Model validations should be run on save()

Reported by: Aaron Smith Owned by: nobody
Component: Database layer (models, ORM) Version: 4.0
Severity: Normal Keywords: model, validation, validations
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description (last modified by Aaron Smith)

Most modern Django applications, at least as far as I have seen in 6 years of mostly working with Django, are headless API apps that do not use Forms. As a matter of fact, I have never used Forms in the several dozen django apps I've worked on, including several mission-critical APIs at multi-hundred-person companies.

Not running validations by default is a serious footgun that has ruined more than one developer's day. Yes, it's in the documentation. But the broad expectation is that a web framework will do this sort of thing by default without extra configuration or overrides. Model validations should function as expected by the naive regardless of how the model is saved.

Ideally the Model class should call full_clean() in it's save method. If this can't be done for backwards compatibility, I propose we add a new ValidatedModel class that subclasses Model. There should be a clear and obvious option to fulfill the basic and reasonable expectations of the new Django developer.

I'm more than happy to make this PR.

Change History (2)

comment:1 by Aaron Smith, 20 months ago

Description: modified (diff)

comment:2 by Mariusz Felisiak, 20 months ago

Resolution: wontfix
Status: newclosed
Type: UncategorizedNew feature

This behavior is by design and it's documented (as you've already noticed). If you want to change design decisions then please first start a discussion on the DevelopersMailingList, where you'll reach a wider audience and see what other think, and follow the guidelines with regards to requesting features. We must reach a strong consensus in the discussion to move it forward.

I propose we add a new ValidatedModel class that subclasses Model.

You can always add and use your own subclass in the code.

Note: See TracTickets for help on using tickets.
Back to Top