Opened 14 years ago

Closed 14 years ago

#13097 closed (duplicate)

Document full_clean() better (include cases where it isn't used)

Reported by: Oroku Saki Owned by: nobody
Component: Documentation Version: 1.2-beta
Severity: Keywords: models, validation
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no


If you read here:

It says that full_clean() is called most of the time by ModelForm. When isn't it called, or better why isn't it called in some cases? Also, where is it called, if it's not called during In clicking through to ModelForm docs (recommended in the section linked above) there is no mention of full_clean(). It might be better to explain the relationship to ModelForm in this section and leave the link out. In my case, I added raise Exception("HELP ME") in a model's clean() method and when saving the model in the admin no exception was raised, which tells me that full_clean() indeed wasn't called. I don't have a suggestion as to how to better document this section because I still haven't solved my problem, but I believe it would really benefit anyone who is using the new model validation.

Change History (3)

comment:1 Changed 14 years ago by Oroku Saki

Update: It mentions running "model validation". However, this doesn't answer why / if Admin doesn't do this.

comment:2 Changed 14 years ago by Oroku Saki

On further investigation, here's what I found (An important bug for those using the new model validation):

BaseForm.is_valid() calls BaseForm._get_errors() calls BaseForm.full_clean() calls BaseForm._post_clean() which calls the following 3 methods:

BaseForm.validate_unique() which calls Model.validate_unique()

Model.full_clean() as defined on line 808 of is never called anywhere in Django, period. This means that the docs are incorrect because ModelForms do not include a call to Model.full_clean(). This means that you cannot use transactions in Model methods (except maybe with hacking) because a full validation from one method isn't included. I'm trying to do this:

    def full_clean(exclude=None):
        super(MyModel, self).full_clean(exclude)
    def clean(self):
        # Creating necessary related instance to attach to self.some_foreign_key (expecting this to be undone buy transaction mentioned above if never completes)

I'll be creating a bug ticket as well with this content, but I wanted to update my documentation ticket so that a decision on it can be made.

comment:3 Changed 14 years ago by jkocherhans

Resolution: duplicate
Status: newclosed

Essentially the same as #13100.

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