#35374: UniqueConstraint (and potentially other constraints) validation is not 
run
when using a form generated from `inlineformset_factory`
----------------------------+--------------------------------------
     Reporter:  David Hang  |                    Owner:  nobody
         Type:  Bug         |                   Status:  closed
    Component:  Forms       |                  Version:
     Severity:  Normal      |               Resolution:  invalid
     Keywords:              |             Triage Stage:  Unreviewed
    Has patch:  0           |      Needs documentation:  0
  Needs tests:  0           |  Patch needs improvement:  0
Easy pickings:  0           |                    UI/UX:  0
----------------------------+--------------------------------------
Changes (by Natalia Bidart):

 * resolution:   => invalid
 * status:  new => closed
 * version:  4.1 =>

Comment:

 Hello David! Thank you for your report.

 Replying to [ticket:35374 David Hang]:
 > Due to how refactors in Django 4+ on how the unique validations are run
 for models and forms

 Could you please provide more concrete information about this affirmation?
 The code you linked hasn't changed in 11 years (except for
 [https://github.com/django/django/pull/15515 a switch to use sets instead
 of lists for the `exclude` variable]) so I'm not sure what refactor in
 Django 4+ you are referring to.

 The example that you provided is a bit tricky/incomplete, because the data
 that is being passed to the formset is incomplete. The data should account
 for the current status of the `Big Farm` instance; this is a correct
 `data` dict example to be passed to the formset:

 {{{
 data = {
     "apple_set-TOTAL_FORMS": "3",
     "apple_set-INITIAL_FORMS": "1",
     "apple_set-0-name": "Best Apple",
     "apple_set-0-farm": big_farm.pk,
     "apple_set-0-id": best_apple.pk,
     "apple_set-1-name": "Best Apple",
     "apple_set-1-farm": big_farm.pk,
     "apple_set-1-id": "",
 }
 }}}

 Then, the expected unique validation is performed. The formset is indeed
 not valid and the errors are:

 {{{#!python
  [{}, {'__all__': ['Please correct the duplicate values below.']}, {}]
 }}}

 I'll be closing this issue as invalid since it could be that you may be
 misunderstanding how formsets works. If you need further assistance, there
 are [https://www.djangoproject.com/community/ many user support channels
 with an amazing community] that will surely help you.
-- 
Ticket URL: <https://code.djangoproject.com/ticket/35374#comment:1>
Django <https://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 unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/0107018ee1d8ce9c-20fcd05b-0b85-4ba7-bd45-b9728bc04ba0-000000%40eu-central-1.amazonses.com.

Reply via email to