Opened 8 years ago
Closed 7 years ago
#28111 closed New feature (needsinfo)
Allow skipping validations done in database for Model.full_clean()
Reported by: | holvianssi | Owned by: | nobody |
---|---|---|---|
Component: | Database layer (models, ORM) | Version: | dev |
Severity: | Normal | Keywords: | |
Cc: | Triage Stage: | Unreviewed | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
A common practice for Model.save() is to do something like:
def save(): self.full_clean() super().save()
The idea is to validate for example field.choices, and other things that aren't checked in database. Unfortunately this also checks unique constraints, foreign keys etc, which is non-necessary in the common case - the checks would be ran in the database in any case, and the db is much faster in checking these constraints.
It would be nice that we could instead do something like this:
def save(): self.full_clean(skip_checks_done_in_database=True) super().save()
This way we would have the additional safety of checking choices and other things that aren't checked in the database, but we wouldn't have overhead of checking a lot of constraints that are already checked in the database.
Change History (2)
comment:1 by , 8 years ago
comment:2 by , 7 years ago
Resolution: | → needsinfo |
---|---|
Status: | new → closed |
I'm not sure how feasible this would be to implement. It seems like that flag would have to be passed all the way to
Field.clean()
and to the field's validators. It's difficult to know which validators are duplicated and which aren't, especially as behavior might vary across databases. Were you thinking of offering a patch?