[Django] #34205: Arrayfield constraint issue in 4.1

4 views
Skip to first unread message

Django

unread,
Dec 9, 2022, 5:08:21 AM12/9/22
to django-...@googlegroups.com
#34205: Arrayfield constraint issue in 4.1
-------------------------------------+-------------------------------------
Reporter: James | Owner: nobody
Gillard |
Type: | Status: new
Uncategorized |
Component: Database | Version: 4.1
layer (models, ORM) |
Severity: Normal | Keywords:
Triage Stage: | Has patch: 0
Unreviewed |
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------+-------------------------------------
I'd already posted this in the django-users groups and someone had
suggested this might be a bug, so am reposting here:

I can't yet work out whether this is a Django bug or how I'm using model
constraints... Just upgraded from 4.0.8 to 4.1.4 and have hit this issue
when saving this model in the admin. I'd read in the release notes that
these constraints would be validated on model save, and that's the code
that's leading to this exception. If it's not something I've done, it
seems ArrayField isn't working with this new validation of my condition.
The same happens for Q(phone_numbers__len__gte=0), and the error
disappears if I comment out this condition. It seems the generated code
might be wrong, as I see 12 "%s" and only 11 elements in params. All it's
trying to do is ensure that an empty list isn't considered unique.

When hitting save I now get {{{ IndexError: tuple index out of range }}}

Here's the failing model:

{{{
phone_numbers = ArrayField(models.CharField(max_length=200), default=list,
blank=True)

class Meta:
constraints = [
models.UniqueConstraint(
fields=['phone_numbers'],
condition=~Q(phone_numbers__len=0),
name='unique_email_phones',
),
]
)
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/34205>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Dec 9, 2022, 5:13:19 AM12/9/22
to django-...@googlegroups.com
#34205: Arrayfield constraint issue in 4.1
-------------------------------------+-------------------------------------
Reporter: James Gillard | Owner: nobody
Type: Uncategorized | Status: new
Component: Database layer | Version: 4.1
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by James Gillard):

* Attachment "Screenshot 2022-12-09 at 10.11.59-min.png" added.

stack trace

Reply all
Reply to author
Forward
0 new messages