#9493: Formsets with data that violates unique constraints across forms are not
marked invalid
-------------------------------+--------------------------------------------
          Reporter:  Alex      |         Owner:  brosner
            Status:  assigned  |     Milestone:         
         Component:  Forms     |       Version:  1.0    
        Resolution:            |      Keywords:         
             Stage:  Accepted  |     Has_patch:  0      
        Needs_docs:  0         |   Needs_tests:  0      
Needs_better_patch:  0         |  
-------------------------------+--------------------------------------------
Comment (by mrts):

 Thanks to you both for working on this!

 I've attached an updated patch with the following minor changes -- sorry
 for the nitpicking, the patch looks generally good and works well. Also,
 note that the updated patch has been tested (both by running the testcase
 and in admin).

 === 1 ===

 Why do we need to copy the list on line 943 of the patch
 {{{
 unique_together = self.forms[0].instance._meta.unique_together[:]
 }}}
 and discard it right afterwards (by reusing the `unique_together` variable
 name on next line)? Wouldn't
 {{{
 unique_together = [check for check in
 self.forms[0].instance._meta.unique_together if [True for field in check
 if field in self.forms[0].fields]]
 }}}
 be more appropriate?

 === 2 ===

 Similarly, wouldn't it make sense to avoid using the `bad_fields`
 intermediary and use `errors` directly instead?

 === 3 ===

 If there is only one field (i.e. it is a ''unique'', not ''unique
 together'' test), it probably makes sense to call `force_unicode` (or
 indeed, just `unicode`) directly instead of `get_text_list`:
 {{{
 if len(unique_check) == 1:
     errors.append(_(u"You have entered duplicate data for %(field)s, all
 %(field)ss should be unique." % { 'field': force_unicode(field), }))
 }}}

 === 4 ===

 I'd say creating `tuple([form.cleaned_data[field] for field in
 unique_check])` twice in `if tuple([form.cleaned_data[field] for field in
 unique_check]) in data: ... else: data.add(tuple([form.cleaned_data[field]
 for field in unique_check]))` should be avoided.

-- 
Ticket URL: <http://code.djangoproject.com/ticket/9493#comment:3>
Django <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