_QuerySet.__nonzero__ returns True for empty query sets with cached results
|Reported by:||Brodie Rao||Owned by:||nobody|
|Component:||Database layer (models, ORM)||Version:||queryset-refactor|
|Has patch:||yes||Needs documentation:||no|
|Needs tests:||no||Patch needs improvement:||no|
Given any sort of model with zero instances/rows, the following will currently occur:
>>> objects = Foo.objects.all() >>> bool(objects) False >>> bool(objects) True
_QuerySet.__nonzero__ unconditionally returns
True when the result cache is populated, even if nothing is in the cache (i.e. there are no results).
I'm attaching a patch that fixes this behavior, and a test case for it.