1
0
mirror of https://github.com/django/django.git synced 2024-12-22 17:16:24 +00:00

Fixed #32714 -- Prevented recreation of migration for Meta.ordering with OrderBy expressions.

Regression in c8b6594305.

Thanks Kevin Marsh for the report.
This commit is contained in:
Simon Charette 2021-05-04 17:49:46 -04:00 committed by Mariusz Felisiak
parent f9f6bd63c9
commit 96f55ccf79
3 changed files with 26 additions and 3 deletions

View File

@ -1192,8 +1192,7 @@ class Exists(Subquery):
return sql, params
@deconstructible
class OrderBy(BaseExpression):
class OrderBy(Expression):
template = '%(expression)s %(ordering)s'
conditional = False

View File

@ -9,4 +9,6 @@ Django 3.2.2 fixes several bugs in 3.2.1.
Bugfixes
========
* ...
* Prevented, following a regression in Django 3.2.1, :djadmin:`makemigrations`
from generating infinite migrations for a model with ``Meta.ordering``
contained ``OrderBy`` expressions (:ticket:`32714`).

View File

@ -2000,3 +2000,25 @@ class ExpressionWrapperTests(SimpleTestCase):
group_by_cols = expr.get_group_by_cols(alias=None)
self.assertEqual(group_by_cols, [expr.expression])
self.assertEqual(group_by_cols[0].output_field, expr.output_field)
class OrderByTests(SimpleTestCase):
def test_equal(self):
self.assertEqual(
OrderBy(F('field'), nulls_last=True),
OrderBy(F('field'), nulls_last=True),
)
self.assertNotEqual(
OrderBy(F('field'), nulls_last=True),
OrderBy(F('field'), nulls_last=False),
)
def test_hash(self):
self.assertEqual(
hash(OrderBy(F('field'), nulls_last=True)),
hash(OrderBy(F('field'), nulls_last=True)),
)
self.assertNotEqual(
hash(OrderBy(F('field'), nulls_last=True)),
hash(OrderBy(F('field'), nulls_last=False)),
)