#28616: DISTINCT ON and update() does the wrong thing
-------------------------------------+-------------------------------------
Reporter: Daniel Keller | Owner: Anvesh
| Mishra
Type: Bug | Status: assigned
Component: Database layer | Version: 1.11
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Anvesh Mishra):
* owner: (none) => Anvesh Mishra
* status: new => assigned
Comment:
On looking into it further it seems like the problem comes because of how
the `QuerySet.update()` works
{{{ #!python
query = self.query.chain(sql.UpdateQuery)
}}}
The Query.chain() changes the class of the current object to UpdateQuery
which removes the previous query as a new object is created i.e
{{{
SELECT DISTINCT ON ("distinct_foo"."num") "distinct_foo"."id",
"distinct_foo"."num", "distinct_foo"."date", "distinct_foo"."flag" FROM
"distinct_foo" ORDER BY "distinct_foo"."num" ASC, "distinct_foo"."date"
DESC
}}}
and then replaces it with
{{{
UPDATE "app_foo" SET "flag" = true; args=(True)
}}}
instead of combining both.
--
Ticket URL: <https://code.djangoproject.com/ticket/28616#comment:6>
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/01070184f67e9f82-13b637ba-c745-4030-9454-5aca74811147-000000%40eu-central-1.amazonses.com.