So you can reproduce this by calling select_related. But my questionis "How does this happen?". What are the lines of code that removethe 5 rows with broken foreign keys from the queryset? I've beendigging through the Django codebase and can't find it.

select_related removes broken Foreign Keys, but How?

On Wed, Jun 16, 2010 at 11:55 PM, ryan <writepyt...@gmail.com> wrote:> I noticed this first in the Django Admin. If you have 100 rows in> Table A, and 5 of those have a foreign key entry pointing to a> nonexistent item in Table B, rather than throwing an error, the admin> displays 95. This happens if you set> list_select_related = True, or if one of the list_display fields is a> ForeignKey. (http://docs.djangoproject.com/en/dev/ref/contrib/admin/> #django.contrib.admin.ModelAdmin.list_select_related)>> So you can reproduce this by calling select_related. But my question> is "How does this happen?". What are the lines of code that remove> the 5 rows with broken foreign keys from the queryset? I've been> digging through the Django codebase and can't find it.

A select_related() is a query that returns all the rows from table Athat have corresponding rows in table B. If a row in A doesn't have acorresponding row in B (which includes the case where A points to anon-existent row in B), then the row from A isn't included, either.