#17712: <model>.objects.none() not always empty -------------------------------------+------------------------------------- Reporter: ventur40 | Owner: nobody Type: Bug | Status: new Component: Database layer | Version: 1.3 (models, ORM) | Resolution: Severity: Normal | Triage Stage: Accepted Keywords: none(), orm, | Needs documentation: 0 queryset, emptyqueryset | Patch needs improvement: 0 Has patch: 0 | UI/UX: 0 Needs tests: 0 | Easy pickings: 0 | -------------------------------------+-------------------------------------
Comment (by akaariai): I don't believe .none().annotate() has this problem. I haven't tried but it is hard to see how that could happen with the current code. Of course, if you have value/values_list in between, then you have problems. I think the best way forward would be to remove the `EmptyQuerySet` altogether. Add a flag to sql.query and a couple of checks in the different compiler/as_sql() methods or into the models.query.`QuerySet`.iterator(). Or just add `NothingNode` into the query.where. The latter is done in the patch attached to #17681. There aren't many needed changes, at least not in the `NothingNode` case. The downside of either of the above is that the operations on an empty queryset are going to be somewhat slower (they actually do something). The upside is that this kind of bug should be less common, and that the queryset actually behaves exactly like the "real" queryset, which is not the case at all now. In addition you get to remove around 200 lines of code. If you want to be technically correct when fixing this ticket and avoid the `EmptyQuerySet` removal you should add `EmptyValuesQuerySet` and `EmptyValuesListQuerySet` classes. I don't like that at all. You could cheat and do "return self" from values and values_list however. I wonder if there are something which I am missing about `EmptyQuerySet`. Backward compatibility perhaps? Should we deal with the `EmptyQuerySet` removal in a different ticket, or hijack this one? -- Ticket URL: <https://code.djangoproject.com/ticket/17712#comment:3> Django <https://code.djangoproject.com/> The Web framework for perfectionists with deadlines. -- You received this message because you are subscribed to the Google Groups "Django updates" group. To post to this group, send email to django-updates@googlegroups.com. To unsubscribe from this group, send email to django-updates+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-updates?hl=en.