Skip to content

Commit

Permalink
[3.2.x] Fixed #32714 -- Prevented recreation of migration for Meta.or…
Browse files Browse the repository at this point in the history
…dering with OrderBy expressions.

Regression in c8b6594.

Thanks Kevin Marsh for the report.

Backport of 96f55cc from main
  • Loading branch information
charettes authored and felixxm committed May 5, 2021
1 parent df801dd commit 364098f
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 3 deletions.
3 changes: 1 addition & 2 deletions django/db/models/expressions.py
Original file line number Diff line number Diff line change
Expand Up @@ -1174,8 +1174,7 @@ def select_format(self, compiler, sql, params):
return sql, params


@deconstructible
class OrderBy(BaseExpression):
class OrderBy(Expression):
template = '%(expression)s %(ordering)s'
conditional = False

Expand Down
4 changes: 3 additions & 1 deletion docs/releases/3.2.2.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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`).
22 changes: 22 additions & 0 deletions tests/expressions/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -1947,3 +1947,25 @@ def test_non_empty_group_by(self):
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)),
)

0 comments on commit 364098f

Please sign in to comment.