티스토리 수익 글 보기

티스토리 수익 글 보기

Refs #7098 — Removed support for passing raw column aliases to order… · django/django@06eec31 · GitHub
Skip to content
/ django Public

Commit 06eec31

Browse files
committed
Refs #7098 — Removed support for passing raw column aliases to order_by().
Per deprecation timeline.
1 parent bf770cc commit 06eec31

File tree

3 files changed

+12
29
lines changed

3 files changed

+12
29
lines changed

django/db/models/sql/query.py

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
import difflib
1111
import functools
1212
import sys
13-
import warnings
1413
from collections import Counter, namedtuple
1514
from collections.abc import Iterator, Mapping
1615
from itertools import chain, count, product
@@ -36,7 +35,6 @@
3635
from django.db.models.sql.where import (
3736
AND, OR, ExtraWhere, NothingNode, WhereNode,
3837
)
39-
from django.utils.deprecation import RemovedInDjango40Warning
4038
from django.utils.functional import cached_property
4139
from django.utils.hashable import make_hashable
4240
from django.utils.tree import Node
@@ -1968,15 +1966,6 @@ def add_ordering(self, *ordering):
19681966
errors = []
19691967
for item in ordering:
19701968
if isinstance(item, str):
1971-
if '.' in item:
1972-
warnings.warn(
1973-
'Passing column raw column aliases to order_by() is '
1974-
'deprecated. Wrap %r in a RawSQL expression before '
1975-
'passing it to order_by().' % item,
1976-
category=RemovedInDjango40Warning,
1977-
stacklevel=3,
1978-
)
1979-
continue
19801969
if item == '?':
19811970
continue
19821971
if item.startswith('-'):

docs/releases/4.0.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,3 +303,5 @@ to remove usage of these features.
303303
* The ``providing_args`` argument for ``django.dispatch.Signal`` is removed.
304304

305305
* The ``list`` message for ``ModelMultipleChoiceField`` is removed.
306+
307+
* Support for passing raw column aliases to ``QuerySet.order_by()`` is removed.

tests/queries/tests.py

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@
1212
from django.db.models.sql.constants import LOUTER
1313
from django.db.models.sql.where import NothingNode, WhereNode
1414
from django.test import SimpleTestCase, TestCase, skipUnlessDBFeature
15-
from django.test.utils import CaptureQueriesContext, ignore_warnings
16-
from django.utils.deprecation import RemovedInDjango40Warning
15+
from django.test.utils import CaptureQueriesContext
1716

1817
from .models import (
1918
FK1, Annotation, Article, Author, BaseA, Book, CategoryItem,
@@ -594,13 +593,6 @@ def test_ticket7155(self):
594593
[datetime.datetime(2007, 12, 19, 0, 0)],
595594
)
596595

597-
@ignore_warnings(category=RemovedInDjango40Warning)
598-
def test_ticket7098(self):
599-
self.assertSequenceEqual(
600-
Item.objects.values('note__note').order_by('queries_note.note', 'id'),
601-
[{'note__note': 'n2'}, {'note__note': 'n3'}, {'note__note': 'n3'}, {'note__note': 'n3'}]
602-
)
603-
604596
def test_order_by_rawsql(self):
605597
self.assertSequenceEqual(
606598
Item.objects.values('note__note').order_by(
@@ -615,15 +607,6 @@ def test_order_by_rawsql(self):
615607
],
616608
)
617609

618-
def test_order_by_raw_column_alias_warning(self):
619-
msg = (
620-
"Passing column raw column aliases to order_by() is deprecated. "
621-
"Wrap 'queries_author.name' in a RawSQL expression before "
622-
"passing it to order_by()."
623-
)
624-
with self.assertRaisesMessage(RemovedInDjango40Warning, msg):
625-
Item.objects.values('creator__name').order_by('queries_author.name')
626-
627610
def test_ticket7096(self):
628611
# Make sure exclude() with multiple conditions continues to work.
629612
self.assertSequenceEqual(
@@ -3083,6 +3066,15 @@ def test_invalid_order_by(self):
30833066
with self.assertRaisesMessage(FieldError, msg):
30843067
Article.objects.order_by('*')
30853068

3069+
def test_invalid_order_by_raw_column_alias(self):
3070+
msg = (
3071+
"Cannot resolve keyword 'queries_author.name' into field. Choices "
3072+
"are: cover, created, creator, creator_id, id, modified, name, "
3073+
"note, note_id, tags"
3074+
)
3075+
with self.assertRaisesMessage(FieldError, msg):
3076+
Item.objects.values('creator__name').order_by('queries_author.name')
3077+
30863078
def test_invalid_queryset_model(self):
30873079
msg = 'Cannot use QuerySet for "Article": Use a QuerySet for "ExtraInfo".'
30883080
with self.assertRaisesMessage(ValueError, msg):

0 commit comments

Comments
 (0)