Opened 6 years ago

Closed 6 years ago

Last modified 6 years ago

#28958 closed Bug (fixed)

Admin changelist crashes when using query expression in the model's Meta.ordering or ModelAdmin.ordering

Reported by: Gabriel Amram Owned by: Mariusz Felisiak
Component: contrib.admin Version: 2.0
Severity: Release blocker Keywords: query expresssion, ordering, admin, meta
Cc: Mariusz Felisiak Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description (last modified by Gabriel Amram)

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

Change History (9)

comment:1 by Gabriel Amram, 6 years ago

Description: modified (diff)
Summary: Using query expression in model Meta.ordering causes AttributeError in adminUsing query expression in either the model's Meta.ordering or ModelAdmin.ordering causes an error

comment:2 by Mariusz Felisiak, 6 years ago

Cc: Mariusz Felisiak added
Triage Stage: UnreviewedAccepted

comment:3 by Tim Graham, 6 years ago

Severity: NormalRelease blocker
Summary: Using query expression in either the model's Meta.ordering or ModelAdmin.ordering causes an errorAdmin changelist crashes when using query expression in the model's Meta.ordering or ModelAdmin.ordering

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

comment:4 by Mariusz Felisiak, 6 years ago

Owner: changed from nobody to Mariusz Felisiak
Status: newassigned

comment:5 by Mariusz Felisiak, 6 years ago

Has patch: set

comment:6 by GitHub <noreply@…>, 6 years ago

Resolution: fixed
Status: assignedclosed

In c815213:

Fixed #28958 -- Fixed admin changelist crash when using a query expression in the page's ordering.

Thanks Tim Graham for the review.

comment:7 by Mariusz Felisiak <felisiak.mariusz@…>, 6 years ago

In b54302d2:

[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

comment:8 by GitHub <noreply@…>, 6 years ago

In 1d00923:

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.

comment:9 by Mariusz Felisiak <felisiak.mariusz@…>, 6 years ago

In 8f67eea:

[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

Note: See TracTickets for help on using tickets.
Back to Top