[Django] #30557: Using Query Expression for ordering in multi-table inheritance scenario triggers TypeError during test

22 views
Skip to first unread message

Django

unread,
Jun 8, 2019, 1:16:33 PM6/8/19
to django-...@googlegroups.com
#30557: Using Query Expression for ordering in multi-table inheritance scenario
triggers TypeError during test
-------------------------------------+-------------------------------------
Reporter: Jonny | Owner: nobody
Fuller |
Type: Bug | Status: new
Component: Database | Version: 2.2
layer (models, ORM) |
Severity: Normal | Keywords: ordering
Triage Stage: | Has patch: 0
Unreviewed |
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------+-------------------------------------
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.

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

Django

unread,
Jun 8, 2019, 1:16:55 PM6/8/19
to django-...@googlegroups.com
#30557: Using Query Expression for ordering in multi-table inheritance scenario
triggers TypeError during test
-------------------------------------+-------------------------------------
Reporter: Jonny Fuller | Owner: nobody
Type: Bug | Status: new
Component: Database layer | Version: 2.2
(models, ORM) |
Severity: Normal | Resolution:
Keywords: ordering | 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 Jonny Fuller:

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>

Django

unread,
Jun 10, 2019, 1:40:41 AM6/10/19
to django-...@googlegroups.com
#30557: order_by() by a parent model crash in multi-table inheritance when
Meta.ordering contains expressions.

-------------------------------------+-------------------------------------
Reporter: Jonny Fuller | Owner: nobody
Type: Bug | Status: new
Component: Database layer | Version: master

(models, ORM) |
Severity: Normal | Resolution:
Keywords: ordering | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0

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

* 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>

Django

unread,
Jun 10, 2019, 1:40:56 AM6/10/19
to django-...@googlegroups.com
#30557: order_by() by a parent model crash in multi-table inheritance when
Meta.ordering contains expressions.
-------------------------------------+-------------------------------------
Reporter: Jonny Fuller | Owner: nobody
Type: Bug | Status: new

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

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

* Attachment "30557.diff" added.

Regression test.

Django

unread,
Jun 10, 2019, 1:49:18 AM6/10/19
to django-...@googlegroups.com
#30557: order_by() a parent model crash when Meta.ordering contains expressions.

-------------------------------------+-------------------------------------
Reporter: Jonny Fuller | Owner: nobody
Type: Bug | Status: new

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

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

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

Django

unread,
Jun 11, 2019, 6:51:47 PM6/11/19
to django-...@googlegroups.com
#30557: order_by() a parent model crash when Meta.ordering contains expressions.
-------------------------------------+-------------------------------------
Reporter: Jonny Fuller | Owner: nobody
Type: Bug | Status: new

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

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

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>

Django

unread,
Jun 12, 2019, 12:59:59 AM6/12/19
to django-...@googlegroups.com
#30557: order_by() a parent model crash when Meta.ordering contains expressions.
-------------------------------------+-------------------------------------
Reporter: Jonny Fuller | Owner: nobody
Type: Bug | Status: new

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

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

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>

Django

unread,
Jun 16, 2019, 3:01:31 AM6/16/19
to django-...@googlegroups.com
#30557: order_by() a parent model crash when Meta.ordering contains expressions.
-------------------------------------+-------------------------------------
Reporter: Jonny Fuller | Owner: Eran
| Keydar
Type: Bug | Status: assigned

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

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

* owner: nobody => Eran Keydar
* status: new => assigned


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

Django

unread,
Jun 19, 2019, 2:24:27 AM6/19/19
to django-...@googlegroups.com
#30557: order_by() a parent model crash when Meta.ordering contains expressions.
-------------------------------------+-------------------------------------
Reporter: Jonny Fuller | Owner: Eran
| Keydar
Type: Bug | Status: assigned
Component: Database layer | Version: master
(models, ORM) |
Severity: Normal | Resolution:
Keywords: ordering | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0

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

* has_patch: 0 => 1


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

Django

unread,
Jun 19, 2019, 2:25:13 AM6/19/19
to django-...@googlegroups.com
#30557: order_by() a parent model crash when Meta.ordering contains expressions.
-------------------------------------+-------------------------------------
Reporter: Jonny Fuller | Owner: Eran
| Keydar
Type: Bug | Status: assigned
Component: Database layer | Version: master
(models, ORM) |
Severity: Normal | Resolution:
Keywords: ordering | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0

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

Comment (by Eran Keydar):

https://github.com/django/django/pull/11489

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

Django

unread,
Jun 20, 2019, 12:44:59 AM6/20/19
to django-...@googlegroups.com
#30557: order_by() a parent model crash when Meta.ordering contains expressions.
-------------------------------------+-------------------------------------
Reporter: Jonny Fuller | Owner: Eran
| Keydar
Type: Bug | Status: assigned
Component: Database layer | Version: master
(models, ORM) |
Severity: Normal | Resolution:
Keywords: ordering | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1

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

* needs_better_patch: 0 => 1


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

Django

unread,
Jul 10, 2019, 6:34:55 AM7/10/19
to django-...@googlegroups.com
#30557: order_by() a parent model crash when Meta.ordering contains expressions.
-------------------------------------+-------------------------------------
Reporter: Jonny Fuller | Owner: Eran
| Keydar
Type: Bug | Status: assigned
Component: Database layer | Version: master
(models, ORM) |
Severity: Normal | Resolution:
Keywords: ordering | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1

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

* cc: Hasan Ramezani (added)


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

Django

unread,
Jul 10, 2019, 3:53:07 PM7/10/19
to django-...@googlegroups.com
#30557: order_by() a parent model crash when Meta.ordering contains expressions.
-------------------------------------+-------------------------------------
Reporter: Jonny Fuller | Owner: (none)
Type: Bug | Status: new

Component: Database layer | Version: master
(models, ORM) |
Severity: Normal | Resolution:
Keywords: ordering | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Eran Keydar):

* owner: Eran Keydar => (none)
* status: assigned => new


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

Django

unread,
Jul 11, 2019, 2:36:05 AM7/11/19
to django-...@googlegroups.com
#30557: order_by() a parent model crash when Meta.ordering contains expressions.
-------------------------------------+-------------------------------------
Reporter: Jonny Fuller | Owner: Hasan
| Ramezani
Type: Bug | Status: assigned

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

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

* 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>

Django

unread,
Jul 11, 2019, 6:07:46 AM7/11/19
to django-...@googlegroups.com
#30557: order_by() a parent model crash when Meta.ordering contains expressions.
-------------------------------------+-------------------------------------
Reporter: Jonny Fuller | Owner: Hasan
| Ramezani
Type: Bug | Status: closed

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

Keywords: ordering | 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 <felisiak.mariusz@…>):

* 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>

Django

unread,
Jul 11, 2019, 7:41:33 AM7/11/19
to django-...@googlegroups.com
#30557: order_by() a parent model crash when Meta.ordering contains expressions.
-------------------------------------+-------------------------------------
Reporter: Jonny Fuller | Owner: Hasan
| Ramezani
Type: Bug | Status: closed
Component: Database layer | Version: master
(models, ORM) |
Severity: Normal | Resolution: fixed
Keywords: ordering | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0

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

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>

Reply all
Reply to author
Forward
0 new messages