#19184: Remove EmptyQuerySet
-------------------------------------+-------------------------------------
               Reporter:  akaariai   |          Owner:  nobody
                   Type:             |         Status:  new
  Cleanup/optimization               |        Version:  1.4
              Component:  Database   |       Keywords:
  layer (models, ORM)                |      Has patch:  1
               Severity:  Normal     |    Needs tests:  0
           Triage Stage:  Design     |  Easy pickings:  0
  decision needed                    |
    Needs documentation:  0          |
Patch needs improvement:  1          |
                  UI/UX:  0          |
-------------------------------------+-------------------------------------
 qs.none() is currently implemented by returning an !EmptyQuerySet which
 has no-op operators for most of the !QuerySet methods.

 This approach has several weaknesses:
   - Doesn't work well with subclasses of !QuerySet (#17271)
   - Doesn't work well when Django uses subclasses internally to implement
 some functionality (values() for example, #15959)
   - The EmptyQS doesn't actually work like !QuerySet - for example
 qs.none().filter(nonexisting_field=someval). Also: #19173.
   - Code duplication: the EmptyQS has around 150 lines of code duplicating
 the methods of QS. The duplicated methods just do return self. If you add
 a method to QS and forget it from EmptyQS strange things can happen.

 Problems if removing EmptyQS:
   - We have documented it in
 
[https://docs.djangoproject.com/en/dev/ref/models/querysets/#django.db.models.query.QuerySet.none
 qs.none()] docs. And, I can't see any way to have a deprecation period for
 this.
   - There will be some performance penalty mainly from queryset cloning as
 the qs.none() methods now actually do something.

 I am obviously +1 to just removing the !EmptyQS. The question is if people
 are relying on isinstance(someqs, !EmptyQuerySet) calls in their code. If
 so, we could add "known_empty" property so that users could check if it is
 possible for this queryset to return any values.

 A work-in-progress patch available from
 [https://github.com/akaariai/django/compare/rm_emptyqs branch
 akaariai/django/rm_emptyqs].

-- 
Ticket URL: <https://code.djangoproject.com/ticket/19184>
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 [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to