Opened 14 years ago

Closed 14 years ago

Last modified 13 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: 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)

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

Download all attachments as: .zip

Change History (4)

by ludovicofischer, 14 years ago

Attachment: model_fullclean.diff added

Model.full_clean() changes

by ludovicofischer, 14 years ago

Attachment: tests.diff added

Test for this case

comment:1 by Béres Botond, 14 years ago

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 by Jacob, 13 years ago

milestone: 1.3

Milestone 1.3 deleted

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