Code

Opened 4 years ago

Closed 4 years ago

Last modified 3 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:

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 4 years ago.
Model.full_clean() changes
tests.diff (2.1 KB) - added by ludovicofischer 4 years ago.
Test for this case

Download all attachments as: .zip

Change History (4)

Changed 4 years ago by ludovicofischer

Model.full_clean() changes

Changed 4 years ago by ludovicofischer

Test for this case

comment:1 Changed 4 years ago by bberes

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Resolution set to invalid
  • Status changed from new to 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.

comment:2 Changed 3 years ago by jacob

  • milestone 1.3 deleted

Milestone 1.3 deleted

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.