A property should say whether the queryset will be ordered or not. I
wanted to use the `qs.ordered` property for this but it seems to stay
truthy, even if the resulting SQL query will not have an ORDER BY clause.
Example:
{{{
qs = Foo.objects.all()
# SQL => 'SELECT "foo_foo"."uuid", "foo_foo"."name" FROM "foo_foo" ORDER
BY "foo_foo"."name" ASC'
qs.ordered # => True
qs.query.default_ordering # => True
############################################
qs2 = Foo.objects.annotate(Count("pk")).all()
# SQL => 'SELECT "foo_foo"."uuid", "foo_foo"."name",
COUNT("foo_foo"."uuid") AS "pk__count" FROM "foo_foo" GROUP BY
"foo_foo"."uuid"'
qs2.ordered # => True
qs2.query.default_ordering # => True
}}}
If it can help : I'm using PostgreSQL
--
Ticket URL: <https://code.djangoproject.com/ticket/31990>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
* status: new => closed
* resolution: => worksforme
Comment:
Thanks for this report, however `QuerySet.ordered` works for me, see
[https://github.com/django/django/blob/502e75f9ed5476ffe8229109acf0c23999d4b533/tests/queries/tests.py#L2082-L2085
tests].
--
Ticket URL: <https://code.djangoproject.com/ticket/31990#comment:1>
* status: closed => new
* resolution: worksforme =>
Comment:
Replying to [comment:1 felixxm]:
> Thanks for this report, however `QuerySet.ordered` works for me, see
[https://github.com/django/django/blob/502e75f9ed5476ffe8229109acf0c23999d4b533/tests/queries/tests.py#L2082-L2085
tests].
Thanks for your answer but I've just checked again as it is in my example
and `ordered` still returns True if an annotation is applied.
As said earlier, my model has a default ordering in the Meta class, the
one in your unit test doesn't have.
If I modify the `Annotation` model to add a default ordering, the test
doesn't pass anymore.
It can be the intended behavior but it just sounds misleading to me
(having an `ordered` property sets to `True` while the results will
**not** be ordered).
--
Ticket URL: <https://code.djangoproject.com/ticket/31990#comment:2>
* cc: Ramiro Morales (added)
* severity: Normal => Release blocker
* stage: Unreviewed => Accepted
Comment:
Thanks for clarification, `Meta.ordering` doesn't affect `GROUP BY`
queries after 0ddb4ebf7bfcc4730c80a772dd146a49ef6895f6 (which was
deprecated in 1b1f64ee5a78cc217fead52cbae23114502cf564). We should adjust
`QuerySet.ordered`.
--
Ticket URL: <https://code.djangoproject.com/ticket/31990#comment:3>
* Attachment "test-31990.diff" added.
Regression test.
* owner: nobody => felixxm
* status: new => assigned
--
Ticket URL: <https://code.djangoproject.com/ticket/31990#comment:4>
* has_patch: 0 => 1
Comment:
[https://github.com/django/django/pull/13417 PR]
--
Ticket URL: <https://code.djangoproject.com/ticket/31990#comment:5>
* status: assigned => closed
* resolution: => fixed
Comment:
In [changeset:"e11d05e0b488a3ff2b3c9d8f2e1e50f471750d6e" e11d05e0]:
{{{
#!CommitTicketReference repository=""
revision="e11d05e0b488a3ff2b3c9d8f2e1e50f471750d6e"
Fixed #31990 -- Fixed QuerySet.ordered for GROUP BY queries on models with
Meta.ordering.
Regression in 0ddb4ebf7bfcc4730c80a772dd146a49ef6895f6.
Thanks Julien Dutriaux for the report.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/31990#comment:6>
Comment (by Mariusz Felisiak <felisiak.mariusz@…>):
In [changeset:"a3bb80dc3186bd4d11b7864268beb88595ab00fd" a3bb80dc]:
{{{
#!CommitTicketReference repository=""
revision="a3bb80dc3186bd4d11b7864268beb88595ab00fd"
[3.1.x] Fixed #31990 -- Fixed QuerySet.ordered for GROUP BY queries on
models with Meta.ordering.
Regression in 0ddb4ebf7bfcc4730c80a772dd146a49ef6895f6.
Thanks Julien Dutriaux for the report.
Backport of e11d05e0b488a3ff2b3c9d8f2e1e50f471750d6e from master
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/31990#comment:7>