I'm intrigued as to how you are getting this failure. The m2m_through
tests have been passing for me for some time (and are passing at the
moment). There haven't been any recent modifications that should be
affecting this test.
Further - looking at the test itself, the logic looks sound - the
distinct() condition is appropriate, and should be sufficient to
eliminate the second "Jim" from the returned data.
So - you _shouldn't_ be getting a failure. Can you elaborate on how
you have generate this failure (i.e., the database you are using,
version numbers for every component in your stack, operating systems,
etc)?
> Code that generates this failure is:-
>
> # QuerySet's distinct() method can correct this problem.
>>>> Person.objects.filter(membership__date_joined__gt=datetime(2004, 1, 1)).distinct()
> [<Person: Jane>, <Person: Jim>]
>
> The reason for this failure is the sql that gets generated for this
> which I printed using as_sql function as:-
>
> ('SELECT DISTINCT "M2M_THROUGH_PERSON"."ID",
> "M2M_THROUGH_PERSON"."NAME" FROM "M2M_THROUGH_PERSON" INNER JOIN
> "M2M_THROUGH_MEMBERSHIP" ON ("M2M_THROUGH_PERSON"."ID" =
> "M2M_THROUGH_MEMBERSHIP"."PERSON_ID") WHERE
> "M2M_THROUGH_MEMBERSHIP"."DATE_JOINED" > %s ORDER BY
> "M2M_THROUGH_PERSON"."NAME" ASC', (u'2004-01-01 00:00:00',))
>
> Since the Person.ID is always distinct, we would always get 3 columns
> as output. To rectify this, the following document potrays a solution
> to use the values from Queryset
Incorrect. You are returning a list of Person objects. The ID is the
ID of the person, which is distinct to the person instance. The
results you are getting in this case should be:
1, Jane
2, Jim
2, Jim
The third row is then eliminated by the distinct call.
Yours,
Russ Magee %-)