[Django] #29009: This queryset contains a reference to an outer query and may only be used in a subquery

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

[Django] #29009: This queryset contains a reference to an outer query and may only be used in a subquery

Django
#29009: This queryset contains a reference to an outer query and may only be used
in a subquery
-------------------------------------+-------------------------------------
               Reporter:  Vasiliy    |          Owner:  nobody
  Maryutenkov                        |
                   Type:             |         Status:  new
  Uncategorized                      |
              Component:  Database   |        Version:  2.0
  layer (models, ORM)                |
               Severity:  Normal     |       Keywords:
           Triage Stage:             |      Has patch:  0
  Unreviewed                         |
    Needs documentation:  0          |    Needs tests:  0
Patch needs improvement:  0          |  Easy pickings:  0
                  UI/UX:  0          |
-------------------------------------+-------------------------------------
 Hello

 I've tried to serialize queryset with Subquery object and it failed with
 that error.
 "This queryset contains a reference to an outer query and may only be used
 in a subquery"

 {{{

 subquery =
 Transaction.objects.filter(user=OuterRef('pk')).values('user').order_by('user').annotate(txs=Count('*')).annotate(txs_value=Sum(F('tx_value')*F('symbol__price_in_eth'))).annotate(txs_value_eur=Sum((F('tx_value')*F('symbol__price_in_eth'))/eur.price_in_eth))
 investors_qs =
 User.objects.filter(ether_wallet__isnull=False).annotate(txs=Subquery(subquery.values('txs')[:1])).annotate(txs_value=Subquery(subquery.values('txs_value')[:1])).annotate(txs_value_eur=Subquery(subquery.values('txs_value_eur')[:1]))

 jsonpickle.encode(investors_qs.query)
  'This queryset contains a reference to an outer query and may '
 ValueError: This queryset contains a reference to an outer query and may
 only be used in a subquery.
 }}}


 is it normal behaviour or a bug?

--
Ticket URL: <https://code.djangoproject.com/ticket/29009>
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 post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/django-updates/050.578be8680a24d2dc266afaae7fa6a51c%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: [Django] #29009: Error using jsonpickle.encode() on a QuerySet with a Subquery: "This queryset contains a reference to an outer query and may only be used in a subquery" (was: This queryset contains a reference to an outer query and may only be used in a subquery)

Django
#29009: Error using  jsonpickle.encode() on a QuerySet with a Subquery: "This
queryset contains a reference to an outer query and may only be used in a
subquery"
-------------------------------------+-------------------------------------
     Reporter:  Vasiliy Maryutenkov  |                    Owner:  nobody
         Type:  Uncategorized        |                   Status:  closed
    Component:  Database layer       |                  Version:  2.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
-------------------------------------+-------------------------------------
Changes (by Tim Graham):

 * status:  new => closed
 * resolution:   => invalid


Comment:

 I'm not sure how `jsonpickle.encode()` works but if it's trying to
 evaluate `investors_qs.query`, as a string, then I see that the exception
 raised is in the path that generates the SQL. In general, "is it a bug?"
 questions should go to our support channels. See
 TicketClosingReasons/UseSupportChannels.

--
Ticket URL: <https://code.djangoproject.com/ticket/29009#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 post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/django-updates/065.6b6381e593ab20a1bf99f7c4b74809b6%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.