summaryrefslogtreecommitdiff
path: root/tests/ordering/tests.py
diff options
context:
space:
mode:
authorJacob Walls <jacobtylerwalls@gmail.com>2026-01-21 18:00:13 -0500
committerJacob Walls <jacobtylerwalls@gmail.com>2026-02-03 08:26:51 -0500
commit881ff2c4830f95fa844d8de5977c06205d45368f (patch)
treecec19d0f451fa7ec643338d8f99cc4f7ddde19a8 /tests/ordering/tests.py
parent90f5b10784ba5bf369caed87640e2b4394ea3314 (diff)
[4.2.x] Refs CVE-2026-1312 -- Raised ValueError when FilteredRelation aliases contain periods.
This prevents failures at the database layer, given that aliases in the ON clause are not quoted. Systematically quoting aliases even in FilteredRelation is tracked in https://code.djangoproject.com/ticket/36795. Backport of 005d60d97c4dfb117503bdb6f2facfcaf9315d84 from main.
Diffstat (limited to 'tests/ordering/tests.py')
-rw-r--r--tests/ordering/tests.py11
1 files changed, 8 insertions, 3 deletions
diff --git a/tests/ordering/tests.py b/tests/ordering/tests.py
index 530a27920e..30da025875 100644
--- a/tests/ordering/tests.py
+++ b/tests/ordering/tests.py
@@ -15,7 +15,6 @@ from django.db.models import (
Value,
)
from django.db.models.functions import Length, Upper
-from django.db.utils import DatabaseError
from django.test import TestCase
from .models import (
@@ -408,13 +407,19 @@ class OrderingTests(TestCase):
self.assertNotEqual(qs[0].headline, "Backdated")
relation = FilteredRelation("author")
- qs2 = Article.objects.annotate(**{crafted: relation}).order_by(crafted)
- with self.assertRaises(DatabaseError):
+ msg = (
+ "FilteredRelation doesn't support aliases with periods "
+ "(got 'ordering_article.pub_date')."
+ )
+ with self.assertRaisesMessage(ValueError, msg):
+ qs2 = Article.objects.annotate(**{crafted: relation}).order_by(crafted)
# Before, unlike F(), which causes ordering expressions to be
# replaced by ordinals like n in ORDER BY n, these were ordered by
# pub_date instead of author.
# The Article model orders by -pk, so sorting on author will place
# first any article by author2 instead of the backdated one.
+ # This assertion is reachable if FilteredRelation.__init__() starts
+ # supporting periods in aliases in the future.
self.assertNotEqual(qs2[0].headline, "Backdated")
def test_order_by_pk(self):