Code

Opened 3 years ago

Closed 18 months ago

#15591 closed Bug (fixed)

ModelForm save() behavior contradicts with Model object validation documentation.

Reported by: vinod@… Owned by: nobody
Component: Documentation Version: 1.2
Severity: Normal Keywords: modelform validation save model object
Cc: Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

The documentation at http://docs.djangoproject.com/en/dev/ref/models/instances/#validating-objectsstates that:
"Note that full_clean() will not be called automatically when you call your model’s save() method, nor as a result of ModelForm validation."

However, this is contradicted by the documentation at http://docs.djangoproject.com/en/dev/topics/forms/modelforms/ that states that:
"Note that save() will raise a ValueError if the data in the form doesn't validate -- i.e., if form.errors evaluates to True."

It appears that save() shouldn't check validation. That's what is_valid() does, throwing a ValidationError if necessary.

Attachments (0)

Change History (7)

comment:1 Changed 3 years ago by ramiro

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Triage Stage changed from Unreviewed to Accepted

comment:2 Changed 3 years ago by lukeplant

  • Type set to Bug

comment:3 Changed 3 years ago by lukeplant

  • Severity set to Normal

comment:4 Changed 2 years ago by aaugustin

  • UI/UX unset

Change UI/UX from NULL to False.

comment:5 Changed 2 years ago by aaugustin

  • Easy pickings unset

Change Easy pickings from NULL to False.

comment:6 Changed 18 months ago by timo

Actually the docs are correct, but I'll add some clarifying text.

comment:7 Changed 18 months ago by Tim Graham <timograham@…>

  • Resolution set to fixed
  • Status changed from new to closed

In d3fd8a151231726adacb99bdbcd573f95ce32262:

Fixed #15591 - Clarified interaction between ModelForm and model validation.

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.