Opened 15 years ago

Closed 14 years ago

#12304 closed (fixed)

modelForm/unique_together error 'Foo bar with this None and None already exists.'

Reported by: johnsmith Owned by: Ramiro Morales
Component: Forms Version: 1.1
Severity: Keywords: ModelForm unique_together unique wwith this None already exists
Cc: Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

"Foo bar with this None and None already exists."

Try to save a combination of foo and bar that already exists using the form below and the
error message says "this None and None", comment out the field
overrides and there's no problem.
Not sure whether the problem is with unique_together or ModelForm.

Models

class Foo(models.Model):
    f = models.IntegerField(unique=True)
    def __unicode__(self):
        return 'Foo with f = %d' % self.f

class Bar(models.Model):
    b = models.IntegerField(unique=True)
    def __unicode__(self):
        return 'Bar with b = %d' % self.b

class FooBar(models.Model):
   foo = models.ForeignKey('Foo')
   bar = models.ForeignKey('Bar')

   class Meta:
       unique_together = (('foo','bar'),)

Form

class FooBarForm(forms.ModelForm):
    foo = forms.ModelChoiceField(Foo.objects.all()) # comment this line out an the error message is correct
    bar = forms.ModelChoiceField(Bar.objects.all()) # comment this line out an the error message is correct

    class Meta:
        model = FooBar

Attachments (2)

12304-ensure-readable-label-in-unique-validation_error-messages.diff (5.0 KB ) - added by Ramiro Morales 15 years ago.
12304-only-tests-trunk-r12159.diff (3.0 KB ) - added by Ramiro Morales 15 years ago.
The previous patch reduced to only contain the regression tests that demonstrate this was solved with the model-validation branch merge

Download all attachments as: .zip

Change History (8)

comment:1 by Karen Tracey, 15 years ago

#12341 reported this problem also for the unique (not unique_together) error message, plus has some description about what is causing it. The two should be fixed at the same time, so that was closed as a dupe of this.

comment:2 by Ramiro Morales, 15 years ago

Has patch: set
Keywords: unique wwith this None already exists added
Owner: changed from nobody to Ramiro Morales
Status: newassigned

comment:3 by Ramiro Morales, 15 years ago

Triage Stage: UnreviewedAccepted

comment:4 by Alex Gaynor, 15 years ago

Triage Stage: AcceptedReady for checkin

by Ramiro Morales, 15 years ago

The previous patch reduced to only contain the regression tests that demonstrate this was solved with the model-validation branch merge

comment:5 by Ramiro Morales, 15 years ago

Current status is:

  1. 12304-ensure-readable-label-in-unique-validation_error-messages.diff-- patch applicable to the 1.1.x branch to fix this issue.
  2. 12304-only-tests-trunk-r12159.diff -- Patch for trunk that only adds the regression tests because there the issue was fixed with the model-validation branch merge.

comment:6 by Honza Král, 14 years ago

Resolution: fixed
Status: assignedclosed

(In [14198]) Fixed #12304 -- regression tests to make sure the validation messages for unique violations are sane, Thanks ramiro!

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