mirror of
https://github.com/django/django.git
synced 2025-08-03 18:38:50 +00:00
Fixed #30715 -- Fixed crash of ArrayField lookups on ArrayAgg annotations over AutoField.
This commit is contained in:
parent
b1f669406f
commit
521308e575
2 changed files with 27 additions and 1 deletions
|
@ -25,6 +25,7 @@ from .models import (
|
|||
)
|
||||
|
||||
try:
|
||||
from django.contrib.postgres.aggregates import ArrayAgg
|
||||
from django.contrib.postgres.fields import ArrayField
|
||||
from django.contrib.postgres.fields.array import IndexTransform, SliceTransform
|
||||
from django.contrib.postgres.forms import (
|
||||
|
@ -280,6 +281,27 @@ class TestQuerying(PostgreSQLTestCase):
|
|||
[]
|
||||
)
|
||||
|
||||
def test_lookups_autofield_array(self):
|
||||
qs = NullableIntegerArrayModel.objects.filter(
|
||||
field__0__isnull=False,
|
||||
).values('field__0').annotate(
|
||||
arrayagg=ArrayAgg('id'),
|
||||
).order_by('field__0')
|
||||
tests = (
|
||||
('contained_by', [self.objs[1].pk, self.objs[2].pk, 0], [2]),
|
||||
('contains', [self.objs[2].pk], [2]),
|
||||
('exact', [self.objs[3].pk], [20]),
|
||||
('overlap', [self.objs[1].pk, self.objs[3].pk], [2, 20]),
|
||||
)
|
||||
for lookup, value, expected in tests:
|
||||
with self.subTest(lookup=lookup):
|
||||
self.assertSequenceEqual(
|
||||
qs.filter(
|
||||
**{'arrayagg__' + lookup: value},
|
||||
).values_list('field__0', flat=True),
|
||||
expected,
|
||||
)
|
||||
|
||||
def test_index(self):
|
||||
self.assertSequenceEqual(
|
||||
NullableIntegerArrayModel.objects.filter(field__0=2),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue