Opened 6 years ago

Closed 6 years ago

#14531 closed (wontfix)

Add validate_unique flag to ModelForm.Meta

Reported by: wogan Owned by: wogan
Component: Forms Version: 1.2
Severity: Keywords:
Cc: Triage Stage: Unreviewed
Has patch: yes Needs documentation: yes
Needs tests: yes Patch needs improvement: yes
Easy pickings: UI/UX:


ModelForm's currently have a wart in that if you override clean()
you have to call super() to ensure that unique constraints are validated.

This can lead to surprises if you haven't read the documentation closely.

It seems to me this would be better as a property on the Meta class.


    class DontCheckForm(ModelForm):
        def clean(self):
	    return self.cleaned_data
	class Meta:
	    model = SomeModel


    class DontCheckForm(ModelForm):
        class Meta:
	    model = SomeModel
	    validate_unique = False

Attachments (1)

validate_unique.patch (1.8 KB) - added by wogan 6 years ago.
Outline of suggested approach

Download all attachments as: .zip

Change History (3)

Changed 6 years ago by wogan

Outline of suggested approach

comment:1 Changed 6 years ago by wogan

  • Needs documentation set
  • Needs tests set
  • Patch needs improvement set

comment:2 Changed 6 years ago by russellm

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

I don't see how adding a new option is a fix for "user needs to read the documentation" -- any new option will also require documentation, and that documentation will need to be read and understood.

If you override a method, you need to call super() to get the superclass' behavior. This is entirely consistent Python idiom. The default implementation of clean() validates all the uniqueness conditions for the model. If you implement clean(), and don't call super(), then you don't get that validation. I don't see the value in adding an option flag to implement behavior.

If your argument is that documentation needs to be improved around the implications of calling super(), then I'm happy to entertain suggestions.

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