#28616: DISTINCT ON and update() does the wrong thing
-------------------------------------+-------------------------------------
               Reporter:  Daniel     |          Owner:  nobody
  Keller                             |
                   Type:  Bug        |         Status:  new
              Component:  Database   |        Version:  1.11
  layer (models, ORM)                |
               Severity:  Normal     |       Keywords:
           Triage Stage:             |      Has patch:  0
  Unreviewed                         |
    Needs documentation:  0          |    Needs tests:  0
Patch needs improvement:  0          |  Easy pickings:  0
                  UI/UX:  0          |
-------------------------------------+-------------------------------------
 If I have a model like

 {{{
 from django.db import models
 from django.utils import timezone

 class Foo(models.Model):
     num = models.IntegerField(default=0)
     date = models.DateTimeField(default=timezone.now)
     flag = models.BooleanField(default=False)
 }}}

 and (with Postgresql) I do
 {{{
 Foo.objects.order_by('num', '-date').distinct('num').only('pk')
 }}}

 I get a query like
 {{{
 SELECT DISTINCT ON ("app_foo"."num") "app_foo"."id" AS Col1 FROM "app_foo"
 ORDER BY "app_foo"."num" ASC, "app_foo"."date" DESC; args=()
 }}}
 which returns the latest `Foo` for each `num`.

 BUT, if I do
 {{{
 Foo.objects.order_by('num', '-date').distinct('num').update(flag=True)
 }}}

 then it executes
 {{{
 UPDATE "app_foo" SET "flag" = true; args=(True)
 }}}
 which updates ''everything''.

 I don't necessarily think that this behaviour should be supported, but it
 would be nice to at least get a `NotImplementedError`.

-- 
Ticket URL: <https://code.djangoproject.com/ticket/28616>
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 django-updates+unsubscr...@googlegroups.com.
To post to this group, send email to django-updates@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/055.d94a17423e189cde46c48c8f34d94e88%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to