Opened 6 years ago

Closed 6 years ago

#28950 closed Bug (fixed)

ArrayField.has_changed() returns True for unchanged fields

Reported by: tejinderss Owned by: vinay karanam
Component: contrib.postgres Version: 1.11
Severity: Normal Keywords:
Cc: Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description (last modified by tejinderss)

I have models Foo and Bar for example:

    from django.contrib.postgres.fields import ArrayField

    class Foo(models.Model):
        field = models.CharField(max_length=200)

    class Bar(models.Model):
        foo = models.OneToOneField(Foo)
        required_field = models.CharField(blank=False)
        array_field = ArrayField(models.CharField(max_length=50, blank=true), blank=True, null=True)

and in the admin.py i have:

    class BarInline(admin.StackedInline):
        model = Bar

    @admin.register(Foo)
    class FooAdmin(admin.ModelAdmin):
        inlines = [BarInline]

Now the issue is on the save form in admin, if i try to create foo instance without providing any bar data in barinline form, i get error that bar's required field is required and if i make all fields optional, it creates the bar instance anyway without any data. I have played with min_num and max_num but in vain.

Attachments (1)

Capture.PNG (30.9 KB ) - added by tejinderss 6 years ago.

Download all attachments as: .zip

Change History (8)

by tejinderss, 6 years ago

Attachment: Capture.PNG added

comment:1 by tejinderss, 6 years ago

Description: modified (diff)

comment:2 by tejinderss, 6 years ago

Description: modified (diff)

comment:3 by Tim Graham, 6 years ago

I can't reproduce the issue given the minimal models and admin that you provided.

comment:4 by tejinderss, 6 years ago

Description: modified (diff)

This bug seems to be valid only when the postgres arrayfield is used in the inline model

comment:5 by Tim Graham, 6 years ago

Component: Uncategorizedcontrib.postgres
Summary: Model with OnetoOneFeild inline in admin cannot be createdArrayField.has_changed() returns True for unchanged fields
Triage Stage: UnreviewedAccepted
Type: UncategorizedBug

The problem is ArrayField.has_changed() returning True even though the field wasn't modified.

comment:6 by vinay karanam, 6 years ago

Owner: changed from nobody to vinay karanam
Status: newassigned

I've raised a PR implementing necessary changes.

comment:7 by Tim Graham <timograham@…>, 6 years ago

Resolution: fixed
Status: assignedclosed

In 6a1957b:

Fixed #28950 -- Fixed ArrayField.has_changed() for empty values.

Note: See TracTickets for help on using tickets.
Back to Top