invalid count result when paired with select_related
|Reported by:||Owned by:||nobody|
|Component:||Database layer (models, ORM)||Version:||1.0|
|Has patch:||no||Needs documentation:||no|
|Needs tests:||no||Patch needs improvement:||no|
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 [<Session: xxx>, <Session: yyy>, <Session: zzz>] >>> p.page(2).object_list