QuerySet should be evaluated when used in boolean tests
|Reported by:||ubernostrum||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.
Adding a __nonzero__ method to QuerySet which does the evaluation would solve this.
Change History (14)
comment:3 Changed 9 years ago by mir@…
- Resolution set to fixed
- Status changed from assigned to closed
comment:4 Changed 8 years ago by mtredinnick
- Resolution fixed deleted
- Status changed from closed to reopened
- Triage Stage changed from Unreviewed to Accepted