#29355: ArrayField in admin inline form try to save null instead default value
---------------------------------------------+------------------------
               Reporter:  Irina Silvestrova  |          Owner:  nobody
                   Type:  Bug                |         Status:  new
              Component:  Uncategorized      |        Version:
               Severity:  Normal             |       Keywords:
           Triage Stage:  Unreviewed         |      Has patch:  0
    Needs documentation:  0                  |    Needs tests:  0
Patch needs improvement:  0                  |  Easy pickings:  0
                  UI/UX:  0                  |
---------------------------------------------+------------------------
 I have buit-in `User` class and the `Employee` class, one-to-one with
 `User`. It has an `ArrayField` inside:
 {{{
 role = ArrayField(
     models.IntegerField(choices=UserRole.choices(), blank=True,
 null=True),
     verbose_name='User Roles', blank=True, default=list
 )
 }}}
 It is not nullable, but has default value.

 In admin, I have the class `EmployeeInline`:
 {{{
 class EmployeeInline(admin.StackedInline):
     model = models.Employee
     can_delete = False
     verbose_name_plural = 'employee'
 }}}
 And use it in the `UserAdmin` class in the following way:
 {{{
 @admin.register(models.User)
 class UserAdmin(DefaultUserAdmin):
     def change_view(self, request, object_id, form_url='',
 extra_context=None):
         self.inlines = [EmployeeInline]
         return super(UserAdmin, self).change_view(
             request, object_id, form_url, extra_context
         )
 }}}
 I see role field correct on the admin page, but if I try to save the model
 without selected role, I have an error:
 {{{
 IntegrityError at /admin/auth/user/232/change/

 null value in column "role" violates not-null constraint
 DETAIL:  Failing row contains (232, , 232, , , , 31, t, f, null, null).
 }}}

-- 
Ticket URL: <https://code.djangoproject.com/ticket/29355>
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 post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/051.f4e1785415d5c38d2808317d1017d597%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to