#28484: QuerySet.extra keyword
-------------------------------------+-------------------------------------
     Reporter:  Antonio Carrasco     |                    Owner:  nobody
         Type:  Uncategorized        |                   Status:  new
    Component:  Database layer       |                  Version:  1.11
  (models, ORM)                      |
     Severity:  Normal               |               Resolution:
     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):

 * component:  Uncategorized => Database layer (models, ORM)


Old description:

> Related to the #extra deprecation
> https://docs.djangoproject.com/en/1.11/ref/models/querysets/#extra
> Given this example:
>
> queryset = Model.objects.all()
> ordered_ids = "1,3,5,7"
> queryset.annotate(custom=RawSQL(f"SELECT FIELD(id, %s)",
> (ordered_ids,))).order_by("custom")
> queryset.extra(select={"custom": f"FIELD(id, {ordered_ids})"},
> order_by=[custom]).distinct()
>

> The result of both queries is different. But executing the ".query" query
> in the Mysql native console, the result is the same.
> The result with #extra is ok (the same the native mysql console returns)
> but the result with annotate is wrong.

New description:

 Related to the #extra deprecation
 https://docs.djangoproject.com/en/1.11/ref/models/querysets/#extra
 Given this example:
 {{{
 queryset = Model.objects.all()
 ordered_ids = "1,3,5,7"
 queryset.annotate(custom=RawSQL(f"SELECT FIELD(id, %s)",
 (ordered_ids,))).order_by("custom")
 queryset.extra(select={"custom": f"FIELD(id, {ordered_ids})"},
 order_by=['custom']).distinct()
 }}}
 The result of both queries is different. But executing the ".query" query
 in the Mysql native console, the result is the same.
 The result with #extra is ok (the same the native mysql console returns)
 but the result with annotate is wrong.

--

Comment:

 I'm unclear what the issue is here. It seems expected that the SQL will be
 different since one queryset uses `distinct()` and the other doesn't.
 Could you clarify why you believe Django is at fault?

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

Reply via email to