Opened 10 years ago

Closed 10 years ago

Last modified 8 years ago

#12636 closed (duplicate)

Validation should allow excluded fields

Reported by: Berislav Lopac Owned by: nobody
Component: Uncategorized Version: 1.2-alpha
Severity: Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no


As of 1.2 alpha 1, the ModelForm validation throws an UnresolvableValidationError in the situation where a required field is excluded in the Meta subclass. I understand the intent behind that, but I believe this is broken; luckily, there is a simple way to implement it a bit differently.

Form is not the same as the Model, and ModelForm is nothing but a shortcut to create a form that follows a Model's fields. If a field is hidden from a Form, it should not evaluate it, and the Model will take care of itself: if the field in question has null=False, the Model's save() method will throw an exception anyway.

Luckily, there is already a mechanism which can help us here: blank=True is used in admin to allow a value, so I think that it should be used with regular ModelForms as well. Currently, the only way to pass the validation is that the Model field has both blank=True and null=True, but this is not what we need here: we need a mechanism to separate form validation from the model.

So I propose that only the blank attribute is validated in the ModelForm for excluded fields: if blank=True a None value is allowed for excluded fields, otherwise a UnresolvableValidationError is thrown.

Change History (3)

comment:1 Changed 10 years ago by Berislav Lopac

Summary: Validation should skip excluded formValidation should allow excluded fields

comment:2 Changed 10 years ago by Karen Tracey

Resolution: duplicate
Status: newclosed

Dupe of #12521 (and others) that was fixed by r12206. There's also a thread on the developer's list (linked in the ticket) that discussed this problem if you want to understand the specifics of the fix.

comment:3 Changed 8 years ago by Jacob

milestone: 1.2

Milestone 1.2 deleted

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