Opened 6 years ago

Closed 6 years ago

Last modified 4 years ago

#12636 closed (duplicate)

Validation should allow excluded fields

Reported by: BerislavLopac 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: UI/UX:


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 6 years ago by BerislavLopac

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Summary changed from Validation should skip excluded form to Validation should allow excluded fields

comment:2 Changed 6 years ago by kmtracey

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

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 4 years ago by jacob

  • milestone 1.2 deleted

Milestone 1.2 deleted

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