#34119: Admin: ArrayField in inlines are not properly validated
-------------------------------------+-------------------------------------
               Reporter:  Benjamin   |          Owner:  nobody
  Rigaud                             |
                   Type:  Bug        |         Status:  new
              Component:             |        Version:  3.2
  Uncategorized                      |       Keywords:  admin, arrayfield,
               Severity:  Normal     |  forms
           Triage Stage:             |      Has patch:  0
  Unreviewed                         |
    Needs documentation:  0          |    Needs tests:  0
Patch needs improvement:  0          |  Easy pickings:  0
                  UI/UX:  0          |
-------------------------------------+-------------------------------------
 When creating an object via the admin, if an inline contains an ArrayField
 in error, the validation will be bypassed (and the inline dismissed) if we
 submit the form a second time (without modification).

 - go to `/admin/my_app/thing/add/`
 - type anything in `plop`
 - submit -> it shows an error on the inline
 - submit again -> no errors, `plop` become unfilled

 {{{
 # models.py

 class Thing(models.Model):
     pass


 class RelatedModel(models.Model):
     thing = models.ForeignKey(Thing, on_delete=models.CASCADE)

     plop = ArrayField(
         models.CharField(max_length=42),
         default=list,
     )


 # admin.py

 class RelatedModelForm(forms.ModelForm):
     def clean(self):
         raise ValidationError("whatever")


 class RelatedModelInline(admin.TabularInline):
     form = RelatedModelForm
     model = RelatedModel
     extra = 1


 @admin.register(Thing)
 class ThingAdmin(admin.ModelAdmin):
     inlines = [
         RelatedModelInline
     ]
 }}}

 It seems related to the hidden input containing the initial value:

 `<input type="hidden" name="initial-relatedmodel_set-0-plop" value="test"
 id="initial-relatedmodel_set-0-id_relatedmodel_set-0-plop">`

 I can fix the issue locally by forcing `show_hidden_initial=False` on the
 field (in the form init)

-- 
Ticket URL: <https://code.djangoproject.com/ticket/34119>
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/010701840ef36596-2319d22e-b67a-421a-b3b1-4c3753d4eb50-000000%40eu-central-1.amazonses.com.

Reply via email to