#28484: QuerySet.extra keyword
----------------------------------+--------------------------------------
     Reporter:  Antonio Carrasco  |                    Owner:  nobody
         Type:  Uncategorized     |                   Status:  new
    Component:  Uncategorized     |                  Version:  1.11
     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
----------------------------------+--------------------------------------
Description changed by Antonio Carrasco:

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.__str__() 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.

--

-- 
Ticket URL: <https://code.djangoproject.com/ticket/28484#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 [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.7fea7b703d88674cc1a03ec1c259327e%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to