[Django] #33304: Window(order_by) should allow usage of descending string syntax to be used

3 afișări
Accesați primul mesaj necitit

Django

necitită,
19 nov. 2021, 13:41:1019.11.2021
– django-...@googlegroups.com
#33304: Window(order_by) should allow usage of descending string syntax to be used
-------------------------------------+-------------------------------------
Reporter: Simon | Owner: nobody
Charette |
Type: | Status: assigned
Cleanup/optimization |
Component: Database | Version: dev
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 |
-------------------------------------+-------------------------------------
The `QuerySet.order_by` and
[https://github.com/django/django/blob/a7e7043c8746933dafce652507d3b821801cdc7d/django/contrib/postgres/aggregates/mixins.py#L11-L14
some aggregates ordering kwarg] allows for the leading dash syntax to be
used but `Window.order_by` doesn't as it solely wraps the provided
`order_by` in `ExpressionList(expressions=order_by)`.

This makes for an inconsistent API so I suggest we reuse the logic in
`OrderableAggMixin.__init__` in `Window.__init__`

As a related note it seems most of the logic of `OrderableAggMixin` could
be simplified by using `ExpressionList`.

It's a shame that we used `ordering` and not `order_by` as a kwarg for
`OrderableAggMixin` as it's now inconsistent. Also not sure how much of a
''public'' API the `OrderBy` expression is but I wish it was initially
named `Sort` (or `Ordering`?) so that we could define

{{{#!python
class OrderBy(ExpressionList):
template = 'ORDER BY %(expressions)'

def __init__(self, *expressions, *extra):
expressions = [
(Sort(F(o[1:]), descending=True) if isinstance(o, str) and
o[0] == '-' else o)
for o in expressions
]
super().__init__(*expressions, **extra)
}}}

And then simply use this abstraction in `Window` and Postgres orderable
aggregates.

Assigning to myself as I plan to have a look at this in next few days.

--
Ticket URL: <https://code.djangoproject.com/ticket/33304>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

necitită,
19 nov. 2021, 13:41:2319.11.2021
– django-...@googlegroups.com
#33304: Window(order_by) should allow usage of descending string syntax to be used
-------------------------------------+-------------------------------------
Reporter: Simon Charette | Owner: Simon
Type: | Charette
Cleanup/optimization | Status: assigned
Component: Database layer | Version: dev
(models, ORM) |
Severity: Normal | Resolution:
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):

* owner: nobody => Simon Charette


--
Ticket URL: <https://code.djangoproject.com/ticket/33304#comment:1>

Django

necitită,
19 nov. 2021, 13:42:1619.11.2021
– django-...@googlegroups.com
#33304: Window(order_by) should allow usage of descending string syntax to be used
-------------------------------------+-------------------------------------
Reporter: Simon Charette | Owner: Simon
Type: | Charette
Cleanup/optimization | Status: assigned
Component: Database layer | Version: dev
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Description changed by Simon Charette:

Old description:

New description:

The `QuerySet.order_by` and
[https://github.com/django/django/blob/a7e7043c8746933dafce652507d3b821801cdc7d/django/contrib/postgres/aggregates/mixins.py#L11-L14
some aggregates ordering kwarg] allows for the leading dash syntax to be
used but `Window.order_by` doesn't as it solely wraps the provided
`order_by` in `ExpressionList(expressions=order_by)`.

This makes for an inconsistent API so I suggest we reuse the logic in
`OrderableAggMixin.__init__` in `Window.__init__`

As a related note it seems most of the logic of `OrderableAggMixin` could
be simplified by using `ExpressionList`.

It's a shame that we used `ordering` and not `order_by` as a kwarg for
`OrderableAggMixin` as it's now inconsistent. Also not sure how much of a
''public'' API the `OrderBy` expression is but I wish it was initially
named `Sort` (or `Ordering`?) so that we could define

{{{#!python
class OrderBy(ExpressionList):
template = 'ORDER BY %(expressions)s'

def __init__(self, *expressions, *extra):
expressions = [

(Sort(F(expr[1:]), descending=True) if isinstance(expr, str)
and expr[0] == '-' else expr)
for expr in expressions
]
super().__init__(*expressions, **extra)
}}}

And then simply use this abstraction in `Window` and Postgres orderable
aggregates.

Assigning to myself as I plan to have a look at this in next few days.

--

--
Ticket URL: <https://code.djangoproject.com/ticket/33304#comment:2>

Django

necitită,
20 nov. 2021, 03:33:0320.11.2021
– django-...@googlegroups.com
#33304: Window(order_by) should allow usage of descending string syntax to be used
-------------------------------------+-------------------------------------
Reporter: Simon Charette | Owner: Simon
Type: | Charette
Cleanup/optimization | Status: assigned
Component: Database layer | Version: dev
(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 Carlton Gibson):

* stage: Unreviewed => Accepted


--
Ticket URL: <https://code.djangoproject.com/ticket/33304#comment:3>

Django

necitită,
22 nov. 2021, 00:22:4422.11.2021
– django-...@googlegroups.com
#33304: Window(order_by) should allow usage of descending string syntax to be used
-------------------------------------+-------------------------------------
Reporter: Simon Charette | Owner: Simon
Type: | Charette
Cleanup/optimization | Status: assigned
Component: Database layer | Version: dev
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Simon Charette):

* has_patch: 0 => 1


--
Ticket URL: <https://code.djangoproject.com/ticket/33304#comment:4>

Django

necitită,
22 nov. 2021, 02:20:1922.11.2021
– django-...@googlegroups.com
#33304: Window(order_by) should allow usage of descending string syntax to be used
-------------------------------------+-------------------------------------
Reporter: Simon Charette | Owner: Simon
| Charette
Type: New feature | Status: assigned

Component: Database layer | Version: dev
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak):

* type: Cleanup/optimization => New feature


--
Ticket URL: <https://code.djangoproject.com/ticket/33304#comment:5>

Django

necitită,
22 nov. 2021, 06:24:1422.11.2021
– django-...@googlegroups.com
#33304: Window(order_by) should allow usage of descending string syntax to be used
-------------------------------------+-------------------------------------
Reporter: Simon Charette | Owner: Simon
| Charette
Type: New feature | Status: assigned
Component: Database layer | Version: dev
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 1
Needs tests: 0 | Patch needs improvement: 1

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak):

* needs_better_patch: 0 => 1
* needs_docs: 0 => 1


--
Ticket URL: <https://code.djangoproject.com/ticket/33304#comment:6>

Django

necitită,
23 nov. 2021, 00:46:3823.11.2021
– django-...@googlegroups.com
#33304: Window(order_by) should allow usage of descending string syntax to be used
-------------------------------------+-------------------------------------
Reporter: Simon Charette | Owner: Simon
| Charette
Type: New feature | Status: assigned
Component: Database layer | Version: dev
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 1
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Simon Charette):

* needs_better_patch: 1 => 0


--
Ticket URL: <https://code.djangoproject.com/ticket/33304#comment:7>

Django

necitită,
23 nov. 2021, 00:46:4223.11.2021
– django-...@googlegroups.com
#33304: Window(order_by) should allow usage of descending string syntax to be used
-------------------------------------+-------------------------------------
Reporter: Simon Charette | Owner: Simon
| Charette
Type: New feature | Status: assigned
Component: Database layer | Version: dev
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Simon Charette):

* needs_docs: 1 => 0


--
Ticket URL: <https://code.djangoproject.com/ticket/33304#comment:8>

Django

necitită,
23 nov. 2021, 02:07:1723.11.2021
– django-...@googlegroups.com
#33304: Window(order_by) should allow usage of descending string syntax to be used
-------------------------------------+-------------------------------------
Reporter: Simon Charette | Owner: Simon
| Charette
Type: New feature | Status: assigned
Component: Database layer | Version: dev
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak):

* stage: Accepted => Ready for checkin


--
Ticket URL: <https://code.djangoproject.com/ticket/33304#comment:9>

Django

necitită,
23 nov. 2021, 03:48:5823.11.2021
– django-...@googlegroups.com
#33304: Window(order_by) should allow usage of descending string syntax to be used
-------------------------------------+-------------------------------------
Reporter: Simon Charette | Owner: Simon
| Charette
Type: New feature | Status: assigned
Component: Database layer | Version: dev
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Mariusz Felisiak <felisiak.mariusz@…>):

In [changeset:"e06dc4571ea9fd5723c8029959b95808be9f8812" e06dc457]:
{{{
#!CommitTicketReference repository=""
revision="e06dc4571ea9fd5723c8029959b95808be9f8812"
Refs #33304 -- Enclosed aggregate ordering logic in an expression.

This greatly simplifies the implementation of contrib.postgres'
OrderableAggMixin and allows for reuse in Window expressions.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/33304#comment:10>

Django

necitită,
23 nov. 2021, 03:48:5923.11.2021
– django-...@googlegroups.com
#33304: Window(order_by) should allow usage of descending string syntax to be used
-------------------------------------+-------------------------------------
Reporter: Simon Charette | Owner: Simon
| Charette
Type: New feature | Status: closed

Component: Database layer | Version: dev
(models, ORM) |
Severity: Normal | Resolution: fixed

Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak <felisiak.mariusz@…>):

* status: assigned => closed
* resolution: => fixed


Comment:

In [changeset:"aec71aaa5b029640ce066fe5dc34f7a0050d50b2" aec71aa]:
{{{
#!CommitTicketReference repository=""
revision="aec71aaa5b029640ce066fe5dc34f7a0050d50b2"
Fixed #33304 -- Allowed passing string expressions to Window(order_by).
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/33304#comment:11>

Răspundeți tuturor
Răspundeți autorului
Redirecționați
0 mesaje noi