summaryrefslogtreecommitdiff
path: root/tests/annotations
diff options
context:
space:
mode:
authorJacob Walls <jacobtylerwalls@gmail.com>2025-02-17 19:27:21 -0500
committerSarah Boyce <42296566+sarahboyce@users.noreply.github.com>2025-06-20 08:25:22 +0200
commit8ede411a81b40ca53362e6788601193c7e56a0cf (patch)
treefa68d8f108d56fcdbcc7ad29ae1a0442260bb50e /tests/annotations
parent56f468681aaedefcdada1b86c441c12ae96e7fea (diff)
Fixed #36152 -- Deprecated use of "%" in column aliases.
Unintentional support existed only on SQLite and Oracle.
Diffstat (limited to 'tests/annotations')
-rw-r--r--tests/annotations/tests.py23
1 files changed, 23 insertions, 0 deletions
diff --git a/tests/annotations/tests.py b/tests/annotations/tests.py
index 6c0d7b668c..eb077fcb57 100644
--- a/tests/annotations/tests.py
+++ b/tests/annotations/tests.py
@@ -39,6 +39,7 @@ from django.db.models.functions import (
from django.db.models.sql.query import get_field_names_from_opts
from django.test import TestCase, skipUnlessDBFeature
from django.test.utils import register_lookup
+from django.utils.deprecation import RemovedInDjango70Warning
from .models import (
Author,
@@ -1157,6 +1158,11 @@ class NonAggregateAnnotationTestCase(TestCase):
def test_alias_sql_injection(self):
crafted_alias = """injected_name" from "annotations_book"; --"""
+ # RemovedInDjango70Warning: When the deprecation ends, replace with:
+ # msg = (
+ # "Column aliases cannot contain whitespace characters, quotation marks, "
+ # "semicolons, percent signs, or SQL comments."
+ # )
msg = (
"Column aliases cannot contain whitespace characters, quotation marks, "
"semicolons, or SQL comments."
@@ -1176,10 +1182,17 @@ class NonAggregateAnnotationTestCase(TestCase):
"ali/*as",
"alias*/",
"alias;",
+ # RemovedInDjango70Warning: When the deprecation ends, add this case.
+ # "alias%",
# [] are used by MSSQL.
"alias[",
"alias]",
]
+ # RemovedInDjango70Warning: When the deprecation ends, replace with:
+ # msg = (
+ # "Column aliases cannot contain whitespace characters, quotation marks, "
+ # "semicolons, percent signs, or SQL comments."
+ # )
msg = (
"Column aliases cannot contain whitespace characters, quotation marks, "
"semicolons, or SQL comments."
@@ -1189,6 +1202,11 @@ class NonAggregateAnnotationTestCase(TestCase):
with self.assertRaisesMessage(ValueError, msg):
Book.objects.annotate(**{crafted_alias: Value(1)})
+ def test_alias_containing_percent_sign_deprecation(self):
+ msg = "Using percent signs in a column alias is deprecated."
+ with self.assertRaisesMessage(RemovedInDjango70Warning, msg):
+ Book.objects.annotate(**{"alias%": Value(1)})
+
@skipUnless(connection.vendor == "postgresql", "PostgreSQL tests")
@skipUnlessDBFeature("supports_json_field")
def test_set_returning_functions(self):
@@ -1476,6 +1494,11 @@ class AliasTests(TestCase):
def test_alias_sql_injection(self):
crafted_alias = """injected_name" from "annotations_book"; --"""
+ # RemovedInDjango70Warning: When the deprecation ends, replace with:
+ # msg = (
+ # "Column aliases cannot contain whitespace characters, quotation marks, "
+ # "semicolons, percent signs, or SQL comments."
+ # )
msg = (
"Column aliases cannot contain whitespace characters, quotation marks, "
"semicolons, or SQL comments."