﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
26178	Weird Queryset Result	Sebastian Heil	nobody	"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."	Uncategorized	closed	Database layer (models, ORM)	1.9	Normal	invalid			Unreviewed	0	0	0	0	0	0
