Opened 8 years ago

Closed 8 years ago

Last modified 7 years ago

#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: UI/UX:


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)

model_fullclean.diff (865 bytes) - added by ludovicofischer 8 years ago.
Model.full_clean() changes
tests.diff (2.1 KB) - added by ludovicofischer 8 years ago.
Test for this case

Download all attachments as: .zip

Change History (4)

Changed 8 years ago by ludovicofischer

Attachment: model_fullclean.diff added

Model.full_clean() changes

Changed 8 years ago by ludovicofischer

Attachment: tests.diff added

Test for this case

comment:1 Changed 8 years ago by Béres Botond

Resolution: invalid
Status: newclosed

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.

comment:2 Changed 7 years ago by Jacob

milestone: 1.3

Milestone 1.3 deleted

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