﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
30715	ArrayField lookups crash on ArrayAgg() over AutoFields.	Mikail	Mariusz Felisiak	"When doing a annotation using the `ArrayAgg()` function over the `id/pk` (`django.db.models.fields.AutoField`) field it is casted to `serial[]` which is an invalid type in pSQL.

From this, we get the following error (caused by https://github.com/django/django/blob/b10d322c41f66dc7c77c36f90a3532269b25ea93/django/contrib/postgres/fields/array.py#L81-L83):
{{{
psycopg2.errors.UndefinedObject: type ""serial[]"" does not exist
LINE 1: ... HAVING ARRAY_AGG(""item_item"".""id"" ) @> ARRAY[1,2]::serial[]
}}}

Example:
{{{
#!python

from django.db import models


class Item(models.Model):
    pass
}}}

{{{
#!python

from django.contrib.postgres.aggregates import ArrayAgg
from django.db.models import F
from django.test import TestCase

from .models import Item


class TestQueryAutoIDAsArray(TestCase):
    def test_query(self):
        qs = Item.objects.annotate(pk_list=ArrayAgg(F(""id"")))
        qs = qs.filter(pk_list__contains=[1, 2])
        assert len(qs[:]) == 0
}}}

Maybe we should cast auto fields to `int[]`?"	Bug	closed	contrib.postgres	dev	Normal	fixed	array, serial, postgres, psql, auto, id	Patryk Zawadzki	Ready for checkin	1	0	0	0	0	0
