#30715: ArrayField is converting AutoField to serial[] being an invalid pSQL 
type
-------------------------------------+-------------------------------------
               Reporter:             |          Owner:  (none)
  NyanKiyoshi                        |
                   Type:  Bug        |         Status:  new
              Component:             |        Version:  2.2
  contrib.postgres                   |       Keywords:  array, serial,
               Severity:  Normal     |  postgres, psql, auto, id
           Triage Stage:             |      Has patch:  0
  Unreviewed                         |
    Needs documentation:  0          |    Needs tests:  0
Patch needs improvement:  0          |  Easy pickings:  0
                  UI/UX:  0          |
-------------------------------------+-------------------------------------
 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[]`?

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

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/054.12d2dfd0e04c9e0865ee1fa95b3cc018%40djangoproject.com.

Reply via email to