During testing I discovered a strange bug when using a query expression
for ordering during multi-table inheritance. You can find the full write
up as well as reproducible test repository
[here](https://github.com/JonnyWaffles/djangoordermetabug). The bug occurs
because the field is an OrderBy object, not a string, during
get_order_dir. The linked stacktrace should make the issue obvious, but
what I don't understand is why it only fails during test db setup, not
during repl or script use. I wish I could help more and come up with a
real solution. Hopefully, this is enough for someone wiser to find the
culprit.
--
Ticket URL: <https://code.djangoproject.com/ticket/30557>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
Old description:
> Hi friends,
>
> During testing I discovered a strange bug when using a query expression
> for ordering during multi-table inheritance. You can find the full write
> up as well as reproducible test repository
> [here](https://github.com/JonnyWaffles/djangoordermetabug). The bug
> occurs because the field is an OrderBy object, not a string, during
> get_order_dir. The linked stacktrace should make the issue obvious, but
> what I don't understand is why it only fails during test db setup, not
> during repl or script use. I wish I could help more and come up with a
> real solution. Hopefully, this is enough for someone wiser to find the
> culprit.
New description:
Hi friends,
During testing I discovered a strange bug when using a query expression
for ordering during multi-table inheritance. You can find the full write
up as well as reproducible test repository
https://github.com/JonnyWaffles/djangoordermetabug. The bug occurs because
the field is an OrderBy object, not a string, during get_order_dir. The
linked stacktrace should make the issue obvious, but what I don't
understand is why it only fails during test db setup, not during repl or
script use. I wish I could help more and come up with a real solution.
Hopefully, this is enough for someone wiser to find the culprit.
--
--
Ticket URL: <https://code.djangoproject.com/ticket/30557#comment:1>
* version: 2.2 => master
* stage: Unreviewed => Accepted
Comment:
Thanks for the report. I attached a regression test.
Reproduced at c498f088c584ec3aff97409fdc11b39b28240de9.
--
Ticket URL: <https://code.djangoproject.com/ticket/30557#comment:2>
* Attachment "30557.diff" added.
Regression test.
--
Ticket URL: <https://code.djangoproject.com/ticket/30557#comment:3>
Comment (by getup8):
I *think* I'm getting a similar (or same) error when adding lowercased
ordering to a model via meta:
{{{
class Recipe(models.Model):
# ...
class Meta:
ordering = (Lower('name'),)
}}}
This works fine in normal views (listing out recipes for instance), but in
the admin, I get the following error:
`'Lower' object is not subscriptable`
which also comes via `get_order_dir()`
--
Ticket URL: <https://code.djangoproject.com/ticket/30557#comment:4>
Comment (by felixxm):
Yes that's the same issue, thanks for another scenario to reproduce it.
--
Ticket URL: <https://code.djangoproject.com/ticket/30557#comment:5>
* owner: nobody => Eran Keydar
* status: new => assigned
--
Ticket URL: <https://code.djangoproject.com/ticket/30557#comment:6>
* has_patch: 0 => 1
--
Ticket URL: <https://code.djangoproject.com/ticket/30557#comment:7>
Comment (by Eran Keydar):
https://github.com/django/django/pull/11489
--
Ticket URL: <https://code.djangoproject.com/ticket/30557#comment:8>
* needs_better_patch: 0 => 1
--
Ticket URL: <https://code.djangoproject.com/ticket/30557#comment:9>
* cc: Hasan Ramezani (added)
--
Ticket URL: <https://code.djangoproject.com/ticket/30557#comment:10>
* owner: Eran Keydar => (none)
* status: assigned => new
--
Ticket URL: <https://code.djangoproject.com/ticket/30557#comment:11>
* status: new => assigned
* needs_better_patch: 1 => 0
* owner: (none) => Hasan Ramezani
Comment:
[https://github.com/django/django/pull/11555 PR]
--
Ticket URL: <https://code.djangoproject.com/ticket/30557#comment:12>
* status: assigned => closed
* resolution: => fixed
Comment:
In [changeset:"8c5f9906c56ac72fc4f13218dd90bdf9bc8a248b" 8c5f9906]:
{{{
#!CommitTicketReference repository=""
revision="8c5f9906c56ac72fc4f13218dd90bdf9bc8a248b"
Fixed #30557 -- Fixed crash of ordering by ptr fields when Meta.ordering
contains expressions.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/30557#comment:13>
Comment (by GitHub <noreply@…>):
In [changeset:"7a42cfcfdc94c1e7cd653f3140b9eb30492bae4f" 7a42cfcf]:
{{{
#!CommitTicketReference repository=""
revision="7a42cfcfdc94c1e7cd653f3140b9eb30492bae4f"
Refs #30557 -- Fixed crash of ordering by ptr fields when Meta.ordering
contains F() expressions.
Thanks Can Sarıgöl for the report.
Follow up to 8c5f9906c56ac72fc4f13218dd90bdf9bc8a248b.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/30557#comment:14>