#31135: OuterRef generates invalid SQL with __in filter.
-------------------------------------+-------------------------------------
     Reporter:  Bernd Wechner        |                    Owner:  nobody
         Type:  Bug                  |                   Status:  closed
    Component:  Database layer       |                  Version:  3.0
  (models, ORM)                      |
     Severity:  Normal               |               Resolution:  invalid
     Keywords:                       |             Triage Stage:
                                     |  Unreviewed
    Has patch:  0                    |      Needs documentation:  0
  Needs tests:  0                    |  Patch needs improvement:  0
Easy pickings:  0                    |                    UI/UX:  0
-------------------------------------+-------------------------------------

Comment (by mgaitan):

 Hi, I'm upgrading a project from 2.1 to 3.2 and also hit this issue.

 My code does something like this

 {{{
         agrupaciones_subquery = (
 AgrupacionCircuitos.objects.filter(id__in=self.agrupaciones_a_considerar())
             .filter(
 id__in=(OuterRef("carga__mesa_categoria__mesa__circuito__agrupaciones"))
             )
             .values_list("id", flat=True)
         )
         return (
             self.votos_reportados(categoria, mesas)
             .values_list("opcion__id")
             .annotate(id_agrupacion=Subquery(agrupaciones_subquery))
             .exclude(id_agrupacion__isnull=True)
             .annotate(sum_votos=Sum("votos"))
         )
 }}}

 I can't change `
 id__in=(OuterRef("carga__mesa_categoria__mesa__circuito__agrupaciones"))`
 by `id=(OuterRef)`    because in my case,  it may contains multiples
 related "agrupaciones" . Which should be the workaround?

 Btw, I also agree with Bernd Wechner about the error raised should be more
 clear.

-- 
Ticket URL: <https://code.djangoproject.com/ticket/31135#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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/071.30bc9c774eb237f4e4b0e34548d333f1%40djangoproject.com.

Reply via email to