[Django] #28958: Using query expression in model Meta.ordering causes AttributeError in admin

4 views
Skip to first unread message

Django

unread,
Dec 24, 2017, 8:17:49 AM12/24/17
to django-...@googlegroups.com
#28958: Using query expression in model Meta.ordering causes AttributeError in
admin
-------------------------------------+-------------------------------------
Reporter: Gabriel | Owner: nobody
Amram |
Type: Bug | Status: new
Component: | Version: 2.0
contrib.admin | Keywords: query expresssion,
Severity: Normal | ordering, admin, meta
Triage Stage: | Has patch: 0
Unreviewed |
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------+-------------------------------------
When using the newly introduced query-expression ordering feature in
either the model's Meta.ordering or in its ModelAdmin causes errors.

Steps to reproduce:
First variant - using the model's Meta.ordering option -

{{{
//models.py
class Game(models.Model):
score = models.IntegerField(null=True)

class Meta:
ordering = [F("score").desc(nulls_last=True)]
...
// admin.py
admin.site.register(Game)
}}}
Accessing the admin site will now give an `AttributeError: 'OrderBy'
object has no attribute 'startswith'`

Variant 2 - Using the ModelAdmin ordering attribute:
{{{
//admin.py
class GameAdmin(models.ModelAdmin):
ordering = [F("score").desc(nulls_last=True)]
}}}

`runserver` fails with error: `TypeError: argument of type 'OrderBy' is
not iterable`

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

Django

unread,
Dec 24, 2017, 8:19:16 AM12/24/17
to django-...@googlegroups.com
#28958: Using query expression in either the model's Meta.ordering or
ModelAdmin.ordering causes an error
-------------------------------------+-------------------------------------
Reporter: Gabriel Amram | Owner: nobody
Type: Bug | Status: new
Component: contrib.admin | Version: 2.0
Severity: Normal | Resolution:
Keywords: query expresssion, | Triage Stage:
ordering, admin, meta | Unreviewed
Has patch: 0 | Needs documentation: 0

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

Old description:

> When using the newly introduced query-expression ordering feature in
> either the model's Meta.ordering or in its ModelAdmin causes errors.
>
> Steps to reproduce:
> First variant - using the model's Meta.ordering option -
>
> {{{
> //models.py
> class Game(models.Model):
> score = models.IntegerField(null=True)
>
> class Meta:
> ordering = [F("score").desc(nulls_last=True)]
> ...
> // admin.py
> admin.site.register(Game)
> }}}
> Accessing the admin site will now give an `AttributeError: 'OrderBy'
> object has no attribute 'startswith'`
>
> Variant 2 - Using the ModelAdmin ordering attribute:
> {{{
> //admin.py
> class GameAdmin(models.ModelAdmin):
> ordering = [F("score").desc(nulls_last=True)]
> }}}
>
> `runserver` fails with error: `TypeError: argument of type 'OrderBy' is
> not iterable`

New description:

Using the newly introduced query-expression ordering feature in either the


model's Meta.ordering or in its ModelAdmin causes errors.

Steps to reproduce:
First variant - using the model's Meta.ordering option -

{{{
//models.py
class Game(models.Model):
score = models.IntegerField(null=True)

class Meta:
ordering = [F("score").desc(nulls_last=True)]
...
// admin.py
admin.site.register(Game)
}}}
Accessing the admin site will now give an `AttributeError: 'OrderBy'
object has no attribute 'startswith'`

Variant 2 - Using the ModelAdmin ordering attribute:
{{{
//admin.py
class GameAdmin(models.ModelAdmin):
ordering = [F("score").desc(nulls_last=True)]
}}}

`runserver` fails with error: `TypeError: argument of type 'OrderBy' is
not iterable`

--

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

Django

unread,
Dec 24, 2017, 10:08:20 AM12/24/17
to django-...@googlegroups.com
#28958: Using query expression in either the model's Meta.ordering or
ModelAdmin.ordering causes an error
-------------------------------------+-------------------------------------
Reporter: Gabriel Amram | Owner: nobody
Type: Bug | Status: new

Component: contrib.admin | Version: 2.0
Severity: Normal | Resolution:
Keywords: query expresssion, | Triage Stage: Accepted
ordering, admin, meta |
Has patch: 0 | Needs documentation: 0

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

* cc: felixxm (added)
* stage: Unreviewed => Accepted


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

Django

unread,
Dec 24, 2017, 6:53:25 PM12/24/17
to django-...@googlegroups.com
#28958: Admin changelist crashes when using query expression in the model's
Meta.ordering or ModelAdmin.ordering

-------------------------------------+-------------------------------------
Reporter: Gabriel Amram | Owner: nobody
Type: Bug | Status: new
Component: contrib.admin | Version: 2.0
Severity: Release blocker | Resolution:

Keywords: query expresssion, | Triage Stage: Accepted
ordering, admin, meta |
Has patch: 0 | Needs documentation: 0

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

* severity: Normal => Release blocker


Comment:

It's a bug in a new feature in 2.0 (#28335).

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

Django

unread,
Dec 25, 2017, 6:21:14 AM12/25/17
to django-...@googlegroups.com
#28958: Admin changelist crashes when using query expression in the model's
Meta.ordering or ModelAdmin.ordering
-------------------------------------+-------------------------------------
Reporter: Gabriel Amram | Owner: felixxm
Type: Bug | Status: assigned

Component: contrib.admin | Version: 2.0
Severity: Release blocker | Resolution:
Keywords: query expresssion, | Triage Stage: Accepted
ordering, admin, meta |
Has patch: 0 | Needs documentation: 0

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

* status: new => assigned
* owner: nobody => felixxm


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

Django

unread,
Dec 26, 2017, 3:09:07 AM12/26/17
to django-...@googlegroups.com
#28958: Admin changelist crashes when using query expression in the model's
Meta.ordering or ModelAdmin.ordering
-------------------------------------+-------------------------------------
Reporter: Gabriel Amram | Owner: felixxm
Type: Bug | Status: assigned
Component: contrib.admin | Version: 2.0
Severity: Release blocker | Resolution:
Keywords: query expresssion, | Triage Stage: Accepted
ordering, admin, meta |
Has patch: 1 | Needs documentation: 0

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

* has_patch: 0 => 1


Comment:

[https://github.com/django/django/pull/9491 PR]

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

Django

unread,
Dec 27, 2017, 12:38:57 PM12/27/17
to django-...@googlegroups.com
#28958: Admin changelist crashes when using query expression in the model's
Meta.ordering or ModelAdmin.ordering
-------------------------------------+-------------------------------------
Reporter: Gabriel Amram | Owner: felixxm
Type: Bug | Status: closed
Component: contrib.admin | Version: 2.0
Severity: Release blocker | Resolution: fixed

Keywords: query expresssion, | Triage Stage: Accepted
ordering, admin, meta |
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by GitHub <noreply@…>):

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


Comment:

In [changeset:"c8152137400b5932578cd1788b79560c9772e56b" c815213]:
{{{
#!CommitTicketReference repository=""
revision="c8152137400b5932578cd1788b79560c9772e56b"
Fixed #28958 -- Fixed admin changelist crash when using a query expression
in the page's ordering.

Thanks Tim Graham for the review.
}}}

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

Django

unread,
Dec 27, 2017, 12:47:06 PM12/27/17
to django-...@googlegroups.com
#28958: Admin changelist crashes when using query expression in the model's
Meta.ordering or ModelAdmin.ordering
-------------------------------------+-------------------------------------
Reporter: Gabriel Amram | Owner: felixxm
Type: Bug | Status: closed
Component: contrib.admin | Version: 2.0
Severity: Release blocker | Resolution: fixed
Keywords: query expresssion, | Triage Stage: Accepted
ordering, admin, meta |
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:"b54302d2269e54cfc2a9594b1f3e652e1fd089ed" b54302d2]:
{{{
#!CommitTicketReference repository=""
revision="b54302d2269e54cfc2a9594b1f3e652e1fd089ed"
[2.0.x] Fixed #28958 -- Fixed admin changelist crash when using a query


expression in the page's ordering.

Thanks Tim Graham for the review.

Backport of c8152137400b5932578cd1788b79560c9772e56b from master
}}}

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

Django

unread,
Dec 27, 2017, 1:47:29 PM12/27/17
to django-...@googlegroups.com
#28958: Admin changelist crashes when using query expression in the model's
Meta.ordering or ModelAdmin.ordering
-------------------------------------+-------------------------------------
Reporter: Gabriel Amram | Owner: felixxm
Type: Bug | Status: closed
Component: contrib.admin | Version: 2.0
Severity: Release blocker | Resolution: fixed
Keywords: query expresssion, | Triage Stage: Accepted
ordering, admin, meta |
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:"1d00923848d504c6132019492b8d5a6cdf8261db" 1d00923]:
{{{
#!CommitTicketReference repository=""
revision="1d00923848d504c6132019492b8d5a6cdf8261db"
Refs #28958 -- Added a test for ModelAdmin with query expressions in
ordering.

This provides additional test coverage but isn't a regression test for
the ticket's issue.
}}}

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

Django

unread,
Dec 27, 2017, 1:51:06 PM12/27/17
to django-...@googlegroups.com
#28958: Admin changelist crashes when using query expression in the model's
Meta.ordering or ModelAdmin.ordering
-------------------------------------+-------------------------------------
Reporter: Gabriel Amram | Owner: felixxm
Type: Bug | Status: closed
Component: contrib.admin | Version: 2.0
Severity: Release blocker | Resolution: fixed
Keywords: query expresssion, | Triage Stage: Accepted
ordering, admin, meta |
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:"8f67eeaef44ae8f1fcb51588a65f7818e4d7a967" 8f67eea]:
{{{
#!CommitTicketReference repository=""
revision="8f67eeaef44ae8f1fcb51588a65f7818e4d7a967"
[2.0.x] Refs #28958 -- Added a test for ModelAdmin with query expressions
in ordering.

This provides additional test coverage but isn't a regression test for
the ticket's issue.

Backport of 1d00923848d504c6132019492b8d5a6cdf8261db from master
}}}

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

Reply all
Reply to author
Forward
0 new messages