mirror of
https://github.com/django/django.git
synced 2025-03-06 07:22:32 +00:00
Refs #33543 -- Made Expression.asc()/desc() and OrderBy raise ValueError when nulls_first/nulls_last=False is passed.
Per deprecation timeline.
This commit is contained in:
parent
98756c685e
commit
94ad46e9d8
@ -2,7 +2,6 @@ import copy
|
|||||||
import datetime
|
import datetime
|
||||||
import functools
|
import functools
|
||||||
import inspect
|
import inspect
|
||||||
import warnings
|
|
||||||
from collections import defaultdict
|
from collections import defaultdict
|
||||||
from decimal import Decimal
|
from decimal import Decimal
|
||||||
from uuid import UUID
|
from uuid import UUID
|
||||||
@ -13,7 +12,6 @@ from django.db.models import fields
|
|||||||
from django.db.models.constants import LOOKUP_SEP
|
from django.db.models.constants import LOOKUP_SEP
|
||||||
from django.db.models.query_utils import Q
|
from django.db.models.query_utils import Q
|
||||||
from django.utils.deconstruct import deconstructible
|
from django.utils.deconstruct import deconstructible
|
||||||
from django.utils.deprecation import RemovedInDjango50Warning
|
|
||||||
from django.utils.functional import cached_property
|
from django.utils.functional import cached_property
|
||||||
from django.utils.hashable import make_hashable
|
from django.utils.hashable import make_hashable
|
||||||
|
|
||||||
@ -1571,16 +1569,7 @@ class OrderBy(Expression):
|
|||||||
if nulls_first and nulls_last:
|
if nulls_first and nulls_last:
|
||||||
raise ValueError("nulls_first and nulls_last are mutually exclusive")
|
raise ValueError("nulls_first and nulls_last are mutually exclusive")
|
||||||
if nulls_first is False or nulls_last is False:
|
if nulls_first is False or nulls_last is False:
|
||||||
# When the deprecation ends, replace with:
|
raise ValueError("nulls_first and nulls_last values must be True or None.")
|
||||||
# raise ValueError(
|
|
||||||
# "nulls_first and nulls_last values must be True or None."
|
|
||||||
# )
|
|
||||||
warnings.warn(
|
|
||||||
"Passing nulls_first=False or nulls_last=False is deprecated, use None "
|
|
||||||
"instead.",
|
|
||||||
RemovedInDjango50Warning,
|
|
||||||
stacklevel=2,
|
|
||||||
)
|
|
||||||
self.nulls_first = nulls_first
|
self.nulls_first = nulls_first
|
||||||
self.nulls_last = nulls_last
|
self.nulls_last = nulls_last
|
||||||
self.descending = descending
|
self.descending = descending
|
||||||
|
@ -1063,11 +1063,6 @@ calling the appropriate methods on the wrapped expression.
|
|||||||
``nulls_first`` and ``nulls_last`` define how null values are sorted.
|
``nulls_first`` and ``nulls_last`` define how null values are sorted.
|
||||||
See :ref:`using-f-to-sort-null-values` for example usage.
|
See :ref:`using-f-to-sort-null-values` for example usage.
|
||||||
|
|
||||||
.. deprecated:: 4.1
|
|
||||||
|
|
||||||
Passing ``nulls_first=False`` or ``nulls_last=False`` to ``asc()``
|
|
||||||
is deprecated. Use ``None`` instead.
|
|
||||||
|
|
||||||
.. method:: desc(nulls_first=None, nulls_last=None)
|
.. method:: desc(nulls_first=None, nulls_last=None)
|
||||||
|
|
||||||
Returns the expression ready to be sorted in descending order.
|
Returns the expression ready to be sorted in descending order.
|
||||||
@ -1075,11 +1070,6 @@ calling the appropriate methods on the wrapped expression.
|
|||||||
``nulls_first`` and ``nulls_last`` define how null values are sorted.
|
``nulls_first`` and ``nulls_last`` define how null values are sorted.
|
||||||
See :ref:`using-f-to-sort-null-values` for example usage.
|
See :ref:`using-f-to-sort-null-values` for example usage.
|
||||||
|
|
||||||
.. deprecated:: 4.1
|
|
||||||
|
|
||||||
Passing ``nulls_first=False`` or ``nulls_last=False`` to ``desc()``
|
|
||||||
is deprecated. Use ``None`` instead.
|
|
||||||
|
|
||||||
.. method:: reverse_ordering()
|
.. method:: reverse_ordering()
|
||||||
|
|
||||||
Returns ``self`` with any modifications required to reverse the sort
|
Returns ``self`` with any modifications required to reverse the sort
|
||||||
|
@ -347,3 +347,7 @@ to remove usage of these features.
|
|||||||
``"django/forms/formsets/default.html"`` templates are removed.
|
``"django/forms/formsets/default.html"`` templates are removed.
|
||||||
|
|
||||||
* The default form and formset rendering style is changed to the div-based.
|
* The default form and formset rendering style is changed to the div-based.
|
||||||
|
|
||||||
|
* Passing ``nulls_first=False`` or ``nulls_last=False`` to ``Expression.asc()``
|
||||||
|
and ``Expression.desc()`` methods, and the ``OrderBy`` expression is no
|
||||||
|
longer allowed.
|
||||||
|
@ -70,7 +70,6 @@ from django.test.utils import (
|
|||||||
isolate_apps,
|
isolate_apps,
|
||||||
register_lookup,
|
register_lookup,
|
||||||
)
|
)
|
||||||
from django.utils.deprecation import RemovedInDjango50Warning
|
|
||||||
from django.utils.functional import SimpleLazyObject
|
from django.utils.functional import SimpleLazyObject
|
||||||
|
|
||||||
from .models import (
|
from .models import (
|
||||||
@ -2632,18 +2631,12 @@ class OrderByTests(SimpleTestCase):
|
|||||||
)
|
)
|
||||||
|
|
||||||
def test_nulls_false(self):
|
def test_nulls_false(self):
|
||||||
# These tests will catch ValueError in Django 5.0 when passing False to
|
msg = "nulls_first and nulls_last values must be True or None."
|
||||||
# nulls_first and nulls_last becomes forbidden.
|
with self.assertRaisesMessage(ValueError, msg):
|
||||||
# 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)
|
OrderBy(F("field"), nulls_first=False)
|
||||||
with self.assertRaisesMessage(RemovedInDjango50Warning, msg):
|
with self.assertRaisesMessage(ValueError, msg):
|
||||||
OrderBy(F("field"), nulls_last=False)
|
OrderBy(F("field"), nulls_last=False)
|
||||||
with self.assertRaisesMessage(RemovedInDjango50Warning, msg):
|
with self.assertRaisesMessage(ValueError, msg):
|
||||||
F("field").asc(nulls_first=False)
|
F("field").asc(nulls_first=False)
|
||||||
with self.assertRaisesMessage(RemovedInDjango50Warning, msg):
|
with self.assertRaisesMessage(ValueError, msg):
|
||||||
F("field").desc(nulls_last=False)
|
F("field").desc(nulls_last=False)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user