[Django] #30715: ArrayField is converting AutoField to serial[] being an invalid pSQL type

classic Classic list List threaded Threaded
9 messages Options
Reply | Threaded
Open this post in threaded view
|

[Django] #30715: ArrayField is converting AutoField to serial[] being an invalid pSQL type

Django
#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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/django-updates/054.12d2dfd0e04c9e0865ee1fa95b3cc018%40djangoproject.com.
Reply | Threaded
Open this post in threaded view
|

Re: [Django] #30715: ArrayField is converting AutoField to serial[] being an invalid pSQL type

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

 * cc: Patryk Zawadzki (added)


--
Ticket URL: <https://code.djangoproject.com/ticket/30715#comment:1>
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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/django-updates/069.2ef7227870228ad1d921683288566800%40djangoproject.com.
Reply | Threaded
Open this post in threaded view
|

Re: [Django] #30715: ArrayField lookups crash on ArrayAgg() over AutoFields. (was: ArrayField is converting AutoField to serial[] being an invalid pSQL type)

Django
In reply to this post by Django
#30715: ArrayField lookups crash on ArrayAgg() over AutoFields.
-------------------------------------+-------------------------------------
     Reporter:  NyanKiyoshi          |                    Owner:  (none)
         Type:  Bug                  |                   Status:  new
    Component:  contrib.postgres     |                  Version:  master
     Severity:  Normal               |               Resolution:
     Keywords:  array, serial,       |             Triage Stage:  Accepted
  postgres, psql, auto, id           |
    Has patch:  0                    |      Needs documentation:  0
  Needs tests:  0                    |  Patch needs improvement:  0
Easy pickings:  0                    |                    UI/UX:  0
-------------------------------------+-------------------------------------
Changes (by felixxm):

 * 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>
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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/django-updates/069.5f22aaefd984c1b41e5a9d8be6086ca5%40djangoproject.com.
Reply | Threaded
Open this post in threaded view
|

Re: [Django] #30715: ArrayField lookups crash on ArrayAgg() over AutoFields.

Django
In reply to this post by Django
#30715: ArrayField lookups crash on ArrayAgg() over AutoFields.
-------------------------------------+-------------------------------------
     Reporter:  NyanKiyoshi          |                    Owner:  Adnan
                                     |  Umer
         Type:  Bug                  |                   Status:  assigned
    Component:  contrib.postgres     |                  Version:  master
     Severity:  Normal               |               Resolution:
     Keywords:  array, serial,       |             Triage Stage:  Accepted
  postgres, psql, auto, id           |
    Has patch:  0                    |      Needs documentation:  0
  Needs tests:  0                    |  Patch needs improvement:  0
Easy pickings:  0                    |                    UI/UX:  0
-------------------------------------+-------------------------------------
Changes (by Adnan Umer):

 * owner:  (none) => Adnan Umer
 * status:  new => assigned


--
Ticket URL: <https://code.djangoproject.com/ticket/30715#comment:3>
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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/django-updates/069.da39ac54380b69d2a56b054b2caefede%40djangoproject.com.
Reply | Threaded
Open this post in threaded view
|

Re: [Django] #30715: ArrayField lookups crash on ArrayAgg() over AutoFields.

Django
In reply to this post by Django
#30715: ArrayField lookups crash on ArrayAgg() over AutoFields.
-------------------------------------+-------------------------------------
     Reporter:  NyanKiyoshi          |                    Owner:  Adnan
                                     |  Umer
         Type:  Bug                  |                   Status:  assigned
    Component:  contrib.postgres     |                  Version:  master
     Severity:  Normal               |               Resolution:
     Keywords:  array, serial,       |             Triage Stage:  Accepted
  postgres, psql, auto, id           |
    Has patch:  0                    |      Needs documentation:  0
  Needs tests:  0                    |  Patch needs improvement:  0
Easy pickings:  0                    |                    UI/UX:  0
-------------------------------------+-------------------------------------

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>
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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/django-updates/069.e1842b572db2ecbd5ec5b8cd971018f8%40djangoproject.com.
Reply | Threaded
Open this post in threaded view
|

Re: [Django] #30715: ArrayField lookups crash on ArrayAgg() over AutoFields.

Django
In reply to this post by Django
#30715: ArrayField lookups crash on ArrayAgg() over AutoFields.
-------------------------------------+-------------------------------------
     Reporter:  NyanKiyoshi          |                    Owner:  Adnan
                                     |  Umer
         Type:  Bug                  |                   Status:  assigned
    Component:  contrib.postgres     |                  Version:  master
     Severity:  Normal               |               Resolution:
     Keywords:  array, serial,       |             Triage Stage:  Accepted
  postgres, psql, auto, id           |
    Has patch:  1                    |      Needs documentation:  0
  Needs tests:  0                    |  Patch needs improvement:  0
Easy pickings:  0                    |                    UI/UX:  0
-------------------------------------+-------------------------------------
Changes (by felixxm):

 * has_patch:  0 => 1


Comment:

 [https://github.com/django/django/pull/11699/ PR]

--
Ticket URL: <https://code.djangoproject.com/ticket/30715#comment:5>
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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/django-updates/069.e6aef40a88ab267e17041ddaa92e6350%40djangoproject.com.
Reply | Threaded
Open this post in threaded view
|

Re: [Django] #30715: ArrayField lookups crash on ArrayAgg() over AutoFields.

Django
In reply to this post by Django
#30715: ArrayField lookups crash on ArrayAgg() over AutoFields.
-------------------------------------+-------------------------------------
     Reporter:  NyanKiyoshi          |                    Owner:  felixxm
         Type:  Bug                  |                   Status:  assigned
    Component:  contrib.postgres     |                  Version:  master
     Severity:  Normal               |               Resolution:
     Keywords:  array, serial,       |             Triage Stage:  Accepted
  postgres, psql, auto, id           |
    Has patch:  1                    |      Needs documentation:  0
  Needs tests:  0                    |  Patch needs improvement:  0
Easy pickings:  0                    |                    UI/UX:  0
-------------------------------------+-------------------------------------
Changes (by Adnan Umer):

 * owner:  Adnan Umer => felixxm


Comment:

 No problem felixxm

--
Ticket URL: <https://code.djangoproject.com/ticket/30715#comment:6>
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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/django-updates/069.a8a260338427d3ad3525341c37be4c57%40djangoproject.com.
Reply | Threaded
Open this post in threaded view
|

Re: [Django] #30715: ArrayField lookups crash on ArrayAgg() over AutoFields.

Django
In reply to this post by Django
#30715: ArrayField lookups crash on ArrayAgg() over AutoFields.
-------------------------------------+-------------------------------------
     Reporter:  NyanKiyoshi          |                    Owner:  felixxm
         Type:  Bug                  |                   Status:  assigned
    Component:  contrib.postgres     |                  Version:  master
     Severity:  Normal               |               Resolution:
     Keywords:  array, serial,       |             Triage Stage:  Ready for
  postgres, psql, auto, id           |  checkin
    Has patch:  1                    |      Needs documentation:  0
  Needs tests:  0                    |  Patch needs improvement:  0
Easy pickings:  0                    |                    UI/UX:  0
-------------------------------------+-------------------------------------
Changes (by Carlton Gibson):

 * stage:  Accepted => Ready for checkin


--
Ticket URL: <https://code.djangoproject.com/ticket/30715#comment:7>
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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/django-updates/069.29777f12b9edc1a0351f45c8864f9749%40djangoproject.com.
Reply | Threaded
Open this post in threaded view
|

Re: [Django] #30715: ArrayField lookups crash on ArrayAgg() over AutoFields.

Django
In reply to this post by Django
#30715: ArrayField lookups crash on ArrayAgg() over AutoFields.
-------------------------------------+-------------------------------------
     Reporter:  NyanKiyoshi          |                    Owner:  felixxm
         Type:  Bug                  |                   Status:  closed
    Component:  contrib.postgres     |                  Version:  master
     Severity:  Normal               |               Resolution:  fixed
     Keywords:  array, serial,       |             Triage Stage:  Ready for
  postgres, psql, auto, id           |  checkin
    Has patch:  1                    |      Needs documentation:  0
  Needs tests:  0                    |  Patch needs improvement:  0
Easy pickings:  0                    |                    UI/UX:  0
-------------------------------------+-------------------------------------
Changes (by Carlton Gibson <carlton@…>):

 * 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>
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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/django-updates/069.3669ad82e84ed5822948d1733e519493%40djangoproject.com.