Opened 4 weeks ago

Last modified 2 weeks ago

#28950 assigned Bug

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 i have:

    class BarInline(admin.StackedInline):
        model = Bar

    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 4 weeks ago.

Download all attachments as: .zip

Change History (7)

Changed 4 weeks ago by tejinderss

Attachment: Capture.PNG added

comment:1 Changed 4 weeks ago by tejinderss

Description: modified (diff)

comment:2 Changed 4 weeks ago by tejinderss

Description: modified (diff)

comment:3 Changed 4 weeks ago by Tim Graham

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

comment:4 Changed 4 weeks 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 3 weeks 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 2 weeks ago by vinay karanam

Owner: changed from nobody to vinay karanam
Status: newassigned

I've raised a PR implementing necessary changes.

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