﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
30463	Deprecation message crashes when using a query expression in Model.ordering.	Jannis Vajen	Ruchit Vithani	"Since updating to Django 2.2 our test suite fails because the newly introduced deprecation warning which warns about Meta.ordering being ignored from Django 3.1 onwards leads to errors when a query expression is used. 

Take a model definition like this as an example:


{{{
class Book
    name = models.CharField(max_length=255)

    class Meta:
        ordering = [F('name',).asc()]
           
}}}

The error happens here:

{{{
File ""django/django/db/models/sql/compiler.py"", line 558, in as_sql
    ""', '"".join(self._meta_ordering)
TypeError: sequence item 0: expected str instance, OrderBy found
}}}

A quick and dirty way around that problem is to join the string representations of all the list items instead of concatenating them directly:

{{{
    warnings.warn(
        ""%s QuerySet won't use Meta.ordering in Django 3.1. ""
        ""Add .order_by('%s') to retain the current query."" % (
            self.query.model.__name__,
            ""', '"".join([str(f) for f in self._meta_ordering])
        ),
    )
}}}
 
Unfortunately this doesn't generate real source code compatible with `.order_by()` because the quotation marks are not correct.
Maybe someone else has a clean solution on how to fix this?  

{{{
- Book QuerySet won't use Meta.ordering in Django 3.1. Add .order_by('name', 'OrderBy(F(price), descending=False)') to retain the current query.                                                                           -                                   -
+ Book QuerySet won't use Meta.ordering in Django 3.1. Add .order_by('name', OrderBy(F('price'), descending=False)) to retain the current query.
}}}


A regression test is available here: https://github.com/jnns/django/tree/meta-ordering-deprecation-warning

"	Bug	closed	Database layer (models, ORM)	2.2	Release blocker	fixed	ordering		Ready for checkin	1	0	0	0	1	0
