1
0
mirror of https://github.com/django/django.git synced 2025-09-25 07:59:11 +00:00

Refs #36152, #35667 -- Used skip_file_prefixes in alias deprecation warning.

Follow-up to 8ede411a81b40ca53362e6788601193c7e56a0cf.
This commit is contained in:
Jacob Walls 2025-09-18 15:50:35 -04:00
parent 23b6594026
commit fd705912ff

View File

@ -10,7 +10,6 @@ all about the internals of models in order to get the information it needs.
import copy import copy
import difflib import difflib
import functools import functools
import inspect
import sys import sys
import warnings import warnings
from collections import Counter, namedtuple from collections import Counter, namedtuple
@ -44,7 +43,7 @@ from django.db.models.query_utils import (
from django.db.models.sql.constants import INNER, LOUTER, ORDER_DIR, SINGLE from django.db.models.sql.constants import INNER, LOUTER, ORDER_DIR, SINGLE
from django.db.models.sql.datastructures import BaseTable, Empty, Join, MultiJoin from django.db.models.sql.datastructures import BaseTable, Empty, Join, MultiJoin
from django.db.models.sql.where import AND, OR, ExtraWhere, NothingNode, WhereNode from django.db.models.sql.where import AND, OR, ExtraWhere, NothingNode, WhereNode
from django.utils.deprecation import RemovedInDjango70Warning from django.utils.deprecation import RemovedInDjango70Warning, django_file_prefixes
from django.utils.functional import cached_property from django.utils.functional import cached_property
from django.utils.regex_helper import _lazy_re_compile from django.utils.regex_helper import _lazy_re_compile
from django.utils.tree import Node from django.utils.tree import Node
@ -1216,15 +1215,10 @@ class Query(BaseExpression):
def check_alias(self, alias): def check_alias(self, alias):
# RemovedInDjango70Warning: When the deprecation ends, remove. # RemovedInDjango70Warning: When the deprecation ends, remove.
if "%" in alias: if "%" in alias:
if "aggregate" in {frame.function for frame in inspect.stack()}:
stacklevel = 5
else:
# annotate(), alias(), and values().
stacklevel = 6
warnings.warn( warnings.warn(
"Using percent signs in a column alias is deprecated.", "Using percent signs in a column alias is deprecated.",
stacklevel=stacklevel,
category=RemovedInDjango70Warning, category=RemovedInDjango70Warning,
skip_file_prefixes=django_file_prefixes(),
) )
if FORBIDDEN_ALIAS_PATTERN.search(alias): if FORBIDDEN_ALIAS_PATTERN.search(alias):
raise ValueError( raise ValueError(