diff options
| author | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2019-08-22 13:56:18 +0200 |
|---|---|---|
| committer | Carlton Gibson <carlton@noumenal.es> | 2019-08-23 10:43:08 +0200 |
| commit | 521308e575e4510ef4256f2ba2943a5e570c9328 (patch) | |
| tree | cf12174aafd4e31951e52550138c799a99d9695b /tests/postgres_tests/test_array.py | |
| parent | b1f669406ff82fcd5fed9f20be258944bd3b3bf9 (diff) | |
Fixed #30715 -- Fixed crash of ArrayField lookups on ArrayAgg annotations over AutoField.
Diffstat (limited to 'tests/postgres_tests/test_array.py')
| -rw-r--r-- | tests/postgres_tests/test_array.py | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/tests/postgres_tests/test_array.py b/tests/postgres_tests/test_array.py index fc4c07ea86..42885e61f6 100644 --- a/tests/postgres_tests/test_array.py +++ b/tests/postgres_tests/test_array.py @@ -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), |
