QuerySet should be evaluated when used in boolean tests
|Reported by:||James Bennett||Owned by:||nobody|
|Component:||Database layer (models, ORM)||Version:||master|
|Cc:||ferringb@…, harish.mallipeddi@…||Triage Stage:||Accepted|
|Has patch:||yes||Needs documentation:||no|
|Needs tests:||no||Patch needs improvement:||no|
Currently, a QuerySet is not evaluated when being used in boolean contexts (e.g., doing
if SomeModel.objects.all():); this leads to counterintuitive behavior, because it will always resolve to a True value regardless of whether it would return any objects when "actually" evaluated.
__nonzero__ method to QuerySet which does the evaluation would solve this.
Change History (14)
comment:4 Changed 10 years ago by
|Status:||closed → reopened|
|Triage Stage:||Unreviewed → Accepted|