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[]`?
--
Ticket URL: <https://code.djangoproject.com/ticket/30715>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
* cc: Patryk Zawadzki (added)
--
Ticket URL: <https://code.djangoproject.com/ticket/30715#comment:1>
* version: 2.2 => master
* stage: Unreviewed => Accepted
Comment:
Thanks for the report, all `ArrayField`'s
[https://github.com/django/django/blob/b10d322c41f66dc7c77c36f90a3532269b25ea93/django/contrib/postgres/fields/array.py#L193-L222
lookups] are affected, using a `Cast()` expression (that already handle
this) instead of `'%s::%s'` should fix this issue (tests should land in
`postgres_tests/test_array.py`).
--
Ticket URL: <https://code.djangoproject.com/ticket/30715#comment:2>
* owner: (none) => Adnan Umer
* status: new => assigned
--
Ticket URL: <https://code.djangoproject.com/ticket/30715#comment:3>
Comment (by felixxm):
Hi Adam I solved this when preparing
[https://github.com/django/django/pull/11699/ PR 11699]. Are you OK to
reassign ticket to me?
--
Ticket URL: <https://code.djangoproject.com/ticket/30715#comment:4>
* has_patch: 0 => 1
Comment:
[https://github.com/django/django/pull/11699/ PR]
--
Ticket URL: <https://code.djangoproject.com/ticket/30715#comment:5>
* owner: Adnan Umer => felixxm
Comment:
No problem felixxm
--
Ticket URL: <https://code.djangoproject.com/ticket/30715#comment:6>
* stage: Accepted => Ready for checkin
--
Ticket URL: <https://code.djangoproject.com/ticket/30715#comment:7>
* status: assigned => closed
* resolution: => fixed
Comment:
In [changeset:"521308e575e4510ef4256f2ba2943a5e570c9328" 521308e5]:
{{{
#!CommitTicketReference repository=""
revision="521308e575e4510ef4256f2ba2943a5e570c9328"
Fixed #30715 -- Fixed crash of ArrayField lookups on ArrayAgg annotations
over AutoField.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/30715#comment:8>
* status: closed => new
* version: master => 2.2
* resolution: fixed =>
Comment:
Hi felixxm, sorry to tell, but this issue still present in Django 2.2.12
and 2.2.x branch as well.
Also it does not affect only `pk` fields, but at least `ForeignKey` too.
Could you please apply your fix to 2.2?
--
Ticket URL: <https://code.djangoproject.com/ticket/30715#comment:9>
* status: new => closed
* version: 2.2 => master
* resolution: => fixed
Comment:
The issue has been present since the feature was introduced. Per our
backporting policy this means it doesn't qualify for a backport to 2.2.x
anymore.
See https://docs.djangoproject.com/en/dev/internals/release-process/ for
more details.
--
Ticket URL: <https://code.djangoproject.com/ticket/30715#comment:10>
Comment (by rizzaro):
Is there a workaround for older versions, felixxm? Thank you
--
Ticket URL: <https://code.djangoproject.com/ticket/30715#comment:11>
Comment (by felixxm):
rizzaro, you can apply the patch to your local version or your own fork.
--
Ticket URL: <https://code.djangoproject.com/ticket/30715#comment:12>