Opened 12 months ago

Closed 8 months 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 12 months ago.

Download all attachments as: .zip

Change History (8)

Changed 12 months ago by tejinderss

Attachment: Capture.PNG added

comment:1 Changed 12 months ago by tejinderss

Description: modified (diff)

comment:2 Changed 12 months ago by tejinderss

Description: modified (diff)

comment:3 Changed 12 months ago by Tim Graham

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

comment:4 Changed 12 months ago by tejinderss

Description: modified (diff)

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

comment:5 Changed 12 months ago by Tim Graham

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 Changed 12 months ago by vinay karanam

Owner: changed from nobody to vinay karanam
Status: newassigned

I've raised a PR implementing necessary changes.

comment:7 Changed 8 months ago by Tim Graham <timograham@…>

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