#14152 closed (invalid)
Model validation: full_clean() should call clean() before clean_fields()
| Reported by: | ludovicofischer | Owned by: | nobody |
|---|---|---|---|
| Component: | Database layer (models, ORM) | Version: | 1.2 |
| Severity: | Keywords: | ||
| Cc: | Triage Stage: | Unreviewed | |
| Has patch: | yes | Needs documentation: | no |
| Needs tests: | no | Patch needs improvement: | no |
| Easy pickings: | no | UI/UX: | no |
Description
If a model field is marked as blank=False, a possibility is to override Model.clean() to set the field to a default value. Unfortunately, Model.full_clean() will still throw an exception, because the exception will be generated by Model.clean_fields() before clean() has a chance to run. This patch interchanges the execution order so as to make clean() run before clean_fields().
Attachments (2)
Change History (4)
by , 15 years ago
| Attachment: | model_fullclean.diff added |
|---|
comment:1 by , 15 years ago
| Resolution: | → invalid |
|---|---|
| Status: | new → closed |
Changing the basic order in which model validation is executed is most probably backwards incompatible. Besides I highly doubt the current order is incorrect.
Also the sample use case is very specific and doesn't make much sense... you have blank=False but still want to allow blank (set a default value when blank). That's basically equivalent with blank=True + setting default.
Model.full_clean() changes