Code

Opened 4 years ago

Closed 4 years ago

#12304 closed (fixed)

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

Reported by: johnsmith Owned by: ramiro
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: UI/UX:

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 4 years ago.
12304-only-tests-trunk-r12159.diff (3.0 KB) - added by ramiro 4 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 Changed 4 years ago by kmtracey

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

#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 Changed 4 years ago by ramiro

  • Has patch set
  • Keywords ModelForm unique wwith this None already exists added; ModelForm, removed
  • Owner changed from nobody to ramiro
  • Status changed from new to assigned

comment:3 Changed 4 years ago by ramiro

  • Triage Stage changed from Unreviewed to Accepted

comment:4 Changed 4 years ago by Alex

  • Triage Stage changed from Accepted to Ready for checkin

Changed 4 years ago by ramiro

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

comment:5 Changed 4 years ago by ramiro

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

  • Resolution set to fixed
  • Status changed from assigned to closed

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

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.