Changes between Version 1 and Version 2 of Ticket #28484


Ignore:
Timestamp:
Aug 9, 2017, 5:35:15 PM (7 years ago)
Author:
Tim Graham
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?

Legend:

Unmodified
Added
Removed
Modified
  • Ticket #28484

    • Property Component UncategorizedDatabase layer (models, ORM)
  • Ticket #28484 – Description

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