#8795: bug in form validation
----------------------------------------+-----------------------------------
          Reporter:  [EMAIL PROTECTED]  |         Owner:  nobody
            Status:  new                |     Milestone:  1.0   
         Component:  Forms              |       Version:  SVN   
        Resolution:                     |      Keywords:        
             Stage:  Unreviewed         |     Has_patch:  0     
        Needs_docs:  0                  |   Needs_tests:  0     
Needs_better_patch:  0                  |  
----------------------------------------+-----------------------------------
Changes (by telenieko):

  * needs_better_patch:  => 0
  * needs_tests:  => 0
  * needs_docs:  => 0

Old description:

> i found this bug
>
> when you have model like this:
>
> class FunkcjeProdukt(models.Model):
>     funkcja = models.ForeignKey(FunkcjeRodzina)
>     produkt = models.ForeignKey(Produkty)
>     wartosc = models.CharField(max_length=255)
>     class Meta:
>         unique_together = ("produkt", "funkcja")
>

> and form from model:
> class FunkcjeProduktForm(ModelForm):
>     wartosc =
> forms.CharField(widget=forms.TextInput(attrs={'size':'40','class':'formularz'}))
>     class Meta:
>         model = FunkcjeProdukt
>         exclude=('produkt','funkcja')
>
> end if you want only edit "wartosc" from existing instance:
> form_fp = FunkcjeProduktForm(data=request.POST,instance=finst)
> if form_fp.is_valid():
>        form_fp.save()
>
> error is throw:
>
> KeyError at /cms/r_produkt/8/
> 'produkt'Request Method:    POST
> Request URL:    http://posiflex.com.pl/cms/r_produkt/8/
> Exception Type:    KeyError
> Exception Value:    'produkt'
> Exception Location:    /home/posiflex/django/forms/models.py in
> validate_unique, line 238
>
> because:
> in  validate_unique() from django/forms/models.py
> line unique_checks = list(self.instance._meta.unique_together[:])
> add 'produkt' and 'funkcja' even when this fields in on exclude list

New description:

 i found this bug

 when you have model like this:

 {{{
 #!python
 class FunkcjeProdukt(models.Model):
     funkcja = models.ForeignKey(FunkcjeRodzina)
     produkt = models.ForeignKey(Produkty)
     wartosc = models.CharField(max_length=255)
     class Meta:
         unique_together = ("produkt", "funkcja")
 }}}

 and form from model:
 {{{
 #!python
 class FunkcjeProduktForm(ModelForm):
     wartosc =
 
forms.CharField(widget=forms.TextInput(attrs={'size':'40','class':'formularz'}))
     class Meta:
         model = FunkcjeProdukt
         exclude=('produkt','funkcja')
 }}}
 end if you want only edit "wartosc" from existing instance:

 {{{
 #!python
 form_fp = FunkcjeProduktForm(data=request.POST,instance=finst)
 if form_fp.is_valid():
        form_fp.save()
 }}}

 error is throw:

 {{{
 #!python
 KeyError at /cms/r_produkt/8/'produkt'
 Request Method:    POST
 Request URL:    http://posiflex.com.pl/cms/r_produkt/8/
 Exception Type:    KeyError
 Exception Value:    'produkt'
 Exception Location:    /home/posiflex/django/forms/models.py in
 validate_unique, line 238
 }}}

 because:
 in  validate_unique() from django/forms/models.py
 line unique_checks = list(self.instance._meta.unique_together[:])
 add 'produkt' and 'funkcja' even when this fields in on exclude list

Comment:

 Rewrote Description to hightlight code and not mess with it.

-- 
Ticket URL: <http://code.djangoproject.com/ticket/8795#comment:1>
Django Code <http://code.djangoproject.com/>
The web framework for perfectionists with deadlines
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to