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
--
Ticket URL: <https://code.djangoproject.com/ticket/30463>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
* type: Uncategorized => Bug
* severity: Normal => Release blocker
Comment:
Thanks for the report!
Reproduced at ef9f2eb69c9396683cefa742bc7d0a0792090e8d.
Regression in 1b1f64ee5a78cc217fead52cbae23114502cf564.
--
Ticket URL: <https://code.djangoproject.com/ticket/30463#comment:1>
* Attachment "ticket-30463.diff" added.
Regression test.
* stage: Unreviewed => Accepted
--
Ticket URL: <https://code.djangoproject.com/ticket/30463#comment:2>
* status: new => assigned
* owner: nobody => Ruchit Vithani
--
Ticket URL: <https://code.djangoproject.com/ticket/30463#comment:3>
Comment (by Ruchit Vithani):
Replying to [comment:2 Carlton Gibson]: Is it alright if I assign this
ticket to me?
--
Ticket URL: <https://code.djangoproject.com/ticket/30463#comment:4>
Comment (by Simon Charette):
Replying to [comment:4 Ruchit Vithani]: Feel free to assign the ticket to
yourself if you plan on working on it.
--
Ticket URL: <https://code.djangoproject.com/ticket/30463#comment:5>
* needs_better_patch: 0 => 1
* has_patch: 0 => 1
--
Ticket URL: <https://code.djangoproject.com/ticket/30463#comment:6>
Comment (by Ruchit Vithani):
Link to patch : [https://github.com/django/django/pull/11377]
--
Ticket URL: <https://code.djangoproject.com/ticket/30463#comment:7>
* needs_better_patch: 1 => 0
* stage: Accepted => Ready for checkin
--
Ticket URL: <https://code.djangoproject.com/ticket/30463#comment:8>
* status: assigned => closed
* resolution: => fixed
Comment:
In [changeset:"04042b2b440f0bf50eb908d52cfe76af430e1738" 04042b2b]:
{{{
#!CommitTicketReference repository=""
revision="04042b2b440f0bf50eb908d52cfe76af430e1738"
Fixed #30463 -- Fixed crash of deprecation message when Meta.ordering
contains expressions.
Regression in 1b1f64ee5a78cc217fead52cbae23114502cf564.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/30463#comment:9>
Comment (by Mariusz Felisiak <felisiak.mariusz@…>):
In [changeset:"db7d7901eeacf37f0a6f124e3733c4f121a23e76" db7d7901]:
{{{
#!CommitTicketReference repository=""
revision="db7d7901eeacf37f0a6f124e3733c4f121a23e76"
[2.2.x] Fixed #30463 -- Fixed crash of deprecation message when
Meta.ordering contains expressions.
Regression in 1b1f64ee5a78cc217fead52cbae23114502cf564.
Backport of 04042b2b440f0bf50eb908d52cfe76af430e1738 from master
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/30463#comment:10>