#28297: Same queryset result in two different queries on ORM
-------------------------------------+-------------------------------------
     Reporter:  Marcus Renno         |                    Owner:  Tom
         Type:  Bug                  |                   Status:  assigned
    Component:  Database layer       |                  Version:  1.11
  (models, ORM)                      |
     Severity:  Normal               |               Resolution:
     Keywords:  join, annotation, F  |             Triage Stage:  Accepted
    Has patch:  1                    |      Needs documentation:  0
  Needs tests:  0                    |  Patch needs improvement:  1
Easy pickings:  0                    |                    UI/UX:  0
-------------------------------------+-------------------------------------

Comment (by Tom):

 Hmm, you're right Simon. I missed the OrderedDict change, and tested
 initially on 1.11 (where it's not applied). With this, on master, the
 results are added deterministically, but the first item is always the
 incorrect join.

 So I don't think my ticket fixes the issue in a convincing way. If you
 extend the example in the ticket with another annotate and filter:

 {{{
 self.queryset = self.queryset.annotate(total=Count('steps__ingredients',
 distinct=True))
 self.queryset = self.queryset.filter(steps__ingredients__pk=1)
 self.queryset =
 self.queryset.annotate(available=Count('steps__ingredients',
 distinct=True))
 self.queryset = self.queryset.filter(steps__ingredients__pk=2)
 self.queryset =
 self.queryset.annotate(available2=Count('steps__ingredients',
 distinct=True))
 self.queryset =
 self.queryset.filter(total=F('available')).filter(total=F('available2'))
 }}}

 Then `reuse` will have *three* aliases found: `[('test_app_recipe_steps',
 'LEFT OUTER JOIN'), ('T6', 'INNER JOIN'), ('T10', 'INNER JOIN')]`

 In this case my patch will fetch T6, and we have the same issue.

--
Ticket URL: <https://code.djangoproject.com/ticket/28297#comment:19>
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 django-updates+unsubscr...@googlegroups.com.
To post to this group, send email to django-updates@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/069.e48c64ac0e51b6cb774a8983eb1dbecf%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to