id,summary,reporter,owner,description,type,status,component,version,severity,resolution,keywords,cc,stage,has_patch,needs_docs,needs_tests,needs_better_patch,easy,ui_ux 13249,Feature request: ModelForm validation error handling after commit=False,Oroku Saki,nobody,"For lack of a good explanation, I'll include an example first: {{{ #First, the models and forms used in example: class Account(models.Model): subdomain = SubdomainField(max_length=25, unique=True) class Administrator(models.Model): account = models.ForeignKey(Account, related_name='administrators') username = LowerAlphanumericField(max_length=50) email = models.EmailField() class Meta: unique_together = (('account', 'username'), ('account', 'email')) class AdministratorForm(ModelForm): class Meta: model = Administrator exclude = ('account',) }}} And, here's the example usage that breaks: {{{ #views.py def create_administrator(request): from django.db.utils import IntegrityError from myproject.apps.account.forms import AdministratorForm if request.method == 'POST': form = AdministratorForm(request.POST) if form.is_valid(): instance = form.save(commit=False) instance.account = request.account # ``account`` is attached to ``request`` in custom middleware. instance.save() # What happens if there is an error here such as IntegrityError with one of the 2 unique_together fields ('username', and 'email'). # You cannot tell which field failed the ``unique_together`` test. validate_unique skips over the excluded fields in the form. # # You could run instance.full_clean() first and catch ValidationErrors and handle them manually, but this would not be very DRY after about 3 views. # I don't know what the new version would be like, but I can imagine a way to validate the instance and then add the errors into the form again or something. }}} I probably made this very confusing, but basically there is no way to use commit=False and still use ModelForm's built-in validation conveniences.",Bug,closed,Forms,dev,Normal,duplicate,,,Design decision needed,0,0,0,0,0,0