#26178: Weird Queryset Result
----------------------------------------------+--------------------
     Reporter:  heseba                        |      Owner:  nobody
         Type:  Uncategorized                 |     Status:  new
    Component:  Database layer (models, ORM)  |    Version:  1.9
     Severity:  Normal                        |   Keywords:
 Triage Stage:  Unreviewed                    |  Has patch:  0
Easy pickings:  0                             |      UI/UX:  0
----------------------------------------------+--------------------
 We want to count how often any airport appears as inbound or outbound
 airport and the sum for a given set of flights for statistics purposes.


 {{{
 flights = .... # flight queryset

 Airport.objects.filter(Q(outbound_flights__in=flights) |
 Q(inbound_flights__in=flight))\
             .annotate(
                 flight_count=Count('outbound_flights') +
 Count('inbound_flights'),
                 outbound_flight_count=Count('outbound_flights'),
                 inbound_flight_count=Count('inbound_flights'),
             )
 }}}

 Supposed we have around 80 flights, so we expect **at most** 160 in the
 counts of any airport.

 However, we get around 760 for the total count of the most frequent
 airport. Other numbers exceed the expected values as well.

 What's wrong here?


 Note: {{{outbound_flights}}} and {{{inbound_flights}}} are the reverse
 ForeignKeys of the model Airport and obviously each flight has one arrival
 and one departure airport.

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

Reply via email to