#35587: Add QuerySet.partition(*args, **kwargs)
-------------------------------------+-------------------------------------
     Reporter:  Micah Cantor         |                    Owner:  (none)
         Type:  New feature          |                   Status:  closed
    Component:  Database layer       |                  Version:  5.0
  (models, ORM)                      |
     Severity:  Normal               |               Resolution:  wontfix
     Keywords:                       |             Triage Stage:
                                     |  Unreviewed
    Has patch:  0                    |      Needs documentation:  0
  Needs tests:  0                    |  Patch needs improvement:  0
Easy pickings:  0                    |                    UI/UX:  0
-------------------------------------+-------------------------------------
Changes (by Simon Charette):

 * resolution:   => wontfix
 * status:  new => closed

Comment:

 I don't think it's worth extending the `Queryset` API with a method that
 can be emulated through various method and would entertain the idea that
 the returned set of objects will always be mutually exclusive. This is not
 a guarantee that the ORM can provide for a few reasons.

 First the querysets are going to reach to the database serially and thus
 they won't be executed against the same ''snapshot'' so an object could be
 changed in a way that makes it appear in both partitions. Secondly, while
 the ORM goes at great length to make `exclude` the complement of `filter`
 
[https://code.djangoproject.com/query?description=~exclude&status=assigned&status=new&order=id&desc=1
 it has a few know bugs] which could also manifest themselves in these
 scenarios.

 You are likely better off with a single query that uses an annotation as
 the Python-level predicate for partitioning

 {{{#!python
 def partition(self, *args, **kwargs):
     queryset = self.annotate(_partition_predicate=Q(*args, **kwargs))
     predicate = attrgetter("_partition_predicate")
     return filter(predicate, queryset), filterfalse(predicate, queryset)
 }}}

 But that doesn't allow chaining which for the aforementioned reasons I
 believe is not achievable.
-- 
Ticket URL: <https://code.djangoproject.com/ticket/35587#comment:1>
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 unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/010701909959e2e6-77a20b11-4081-4f70-a658-f9f2d86289e8-000000%40eu-central-1.amazonses.com.

Reply via email to