diff options
| author | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2022-05-12 11:30:03 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-05-12 11:30:03 +0200 |
| commit | 68da6b389c403cb91650754be0e2287696807333 (patch) | |
| tree | a5dce4df79bc4e4d54632864f861705a0e530bba /tests/expressions | |
| parent | 2798c937deb6625a4e6a36e70d4d60ce5faac954 (diff) | |
Fixed #33543 -- Deprecated passing nulls_first/nulls_last=False to OrderBy and Expression.asc()/desc().
Thanks Allen Jonathan David for the initial patch.
Diffstat (limited to 'tests/expressions')
| -rw-r--r-- | tests/expressions/tests.py | 22 |
1 files changed, 20 insertions, 2 deletions
diff --git a/tests/expressions/tests.py b/tests/expressions/tests.py index 72e6020fa0..39e6c18b1a 100644 --- a/tests/expressions/tests.py +++ b/tests/expressions/tests.py @@ -69,6 +69,7 @@ from django.test.utils import ( isolate_apps, register_lookup, ) +from django.utils.deprecation import RemovedInDjango50Warning from django.utils.functional import SimpleLazyObject from .models import ( @@ -2537,7 +2538,7 @@ class OrderByTests(SimpleTestCase): ) self.assertNotEqual( OrderBy(F("field"), nulls_last=True), - OrderBy(F("field"), nulls_last=False), + OrderBy(F("field")), ) def test_hash(self): @@ -2547,5 +2548,22 @@ class OrderByTests(SimpleTestCase): ) self.assertNotEqual( hash(OrderBy(F("field"), nulls_last=True)), - hash(OrderBy(F("field"), nulls_last=False)), + hash(OrderBy(F("field"))), ) + + def test_nulls_false(self): + # These tests will catch ValueError in Django 5.0 when passing False to + # nulls_first and nulls_last becomes forbidden. + # msg = "nulls_first and nulls_last values must be True or None." + msg = ( + "Passing nulls_first=False or nulls_last=False is deprecated, use None " + "instead." + ) + with self.assertRaisesMessage(RemovedInDjango50Warning, msg): + OrderBy(F("field"), nulls_first=False) + with self.assertRaisesMessage(RemovedInDjango50Warning, msg): + OrderBy(F("field"), nulls_last=False) + with self.assertRaisesMessage(RemovedInDjango50Warning, msg): + F("field").asc(nulls_first=False) + with self.assertRaisesMessage(RemovedInDjango50Warning, msg): + F("field").desc(nulls_last=False) |
