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 9041,invalid count result when paired with select_related,Mathieu Bouchard ,nobody,"When using a select_related, I sometimes get invalid results if the select_related method reject some data because they are not valid. If, for example, I have a model that requires a reference to another object and that reference is, for some reason, None, these entries will be rejected by the select_related. The problem is that the Paginator object uses the count method to tell the user how many items are found, but when we try to use these items, we only get an empty page. {{{ >>> a = Session.objects.filter(Key__value = ""www"").select_related() >>> a.count() 29L >>> len(a) 3 }}} {{{ >>> from django.core.paginator import Paginator >>> from metrix2.manager.models import Session >>> q = Session.objects.filter(Key__string = ""2PSpuaRIZGNj"").select_related() >>> p = Paginator(q, 15) >>> p.count 29L >>> p.num_pages 2 >>> p.page(1).object_list [, , ] >>> p.page(2).object_list [] }}}",,closed,"Database layer (models, ORM)",1.0,,invalid,,,Accepted,0,0,0,0,0,0