--
Ticket URL: <https://code.djangoproject.com/ticket/32662>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
Old description:
> I noticed that `SQLCompiler.get_order_by()` has a 70-line
> [https://github.com/django/django/blob/aa4acc164d1247c0de515c959f7b09648b57dc42/django/db/models/sql/compiler.py#L297-L368
> chunk of code] whose job is to build up an `order_by` list, which is then
> iterated over
> [https://github.com/django/django/blob/aa4acc164d1247c0de515c959f7b09648b57dc42/django/db/models/sql/compiler.py#L372
> right after]. That chunk of code has 8 `order_by.append()` lines. It
> looks like this could be made cleaner by pulling those lines out into a
> private method that is instead a generator that yields those pairs. That
> would eliminate the need for having `order_by.append()` in several spots,
> and it would reduce the size of the method into two smaller methods.
New description:
I noticed that `SQLCompiler.get_order_by()` has a 70-line
[https://github.com/django/django/blob/aa4acc164d1247c0de515c959f7b09648b57dc42/django/db/models/sql/compiler.py#L297-L368
chunk of code] whose job is to build up an `order_by` list, which is then
iterated over
[https://github.com/django/django/blob/aa4acc164d1247c0de515c959f7b09648b57dc42/django/db/models/sql/compiler.py#L372
right after]. That chunk of code has 8 `order_by.append()` lines and an
[https://github.com/django/django/blob/aa4acc164d1247c0de515c959f7b09648b57dc42/django/db/models/sql/compiler.py#L357-L358
order_by.extend()]. It looks like this could be made cleaner by pulling
those lines out into a private method that is instead a generator that
yields those pairs. That would eliminate the need for having
`order_by.append()` in several spots, and it would reduce the size of the
method into two smaller methods.
--
--
Ticket URL: <https://code.djangoproject.com/ticket/32662#comment:1>
* component: Uncategorized => Database layer (models, ORM)
* stage: Unreviewed => Accepted
--
Ticket URL: <https://code.djangoproject.com/ticket/32662#comment:2>
* owner: nobody => Chris Jerdonek
* status: new => assigned
--
Ticket URL: <https://code.djangoproject.com/ticket/32662#comment:3>
* has_patch: 0 => 1
Comment:
PR: https://github.com/django/django/pull/14292
--
Ticket URL: <https://code.djangoproject.com/ticket/32662#comment:4>
* stage: Accepted => Ready for checkin
--
Ticket URL: <https://code.djangoproject.com/ticket/32662#comment:5>
* status: assigned => closed
* resolution: => fixed
Comment:
In [changeset:"0461b7a6b62a5acd0db47f8dd76f3dfe7c62b0f5" 0461b7a6]:
{{{
#!CommitTicketReference repository=""
revision="0461b7a6b62a5acd0db47f8dd76f3dfe7c62b0f5"
Fixed #32662 -- Refactored a generator out of SQLCompiler.get_order_by().
This also renames the `asc` variable to `default_order`, markes the
`desc` variable as unused, fixes a typo in SQLCompiler.get_order_by()
docstring, and reorders some blocks in SQLCompiler._order_by_pairs().
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/32662#comment:6>