mirror of
https://github.com/django/django.git
synced 2024-12-23 01:25:58 +00:00
Refs #30158 -- Made alias argument required in signature of Expression.get_group_by_cols() subclasses.
Per deprecation timeline.
This commit is contained in:
parent
d134b0b93e
commit
5e33ec80d1
@ -9,7 +9,6 @@ all about the internals of models in order to get the information it needs.
|
||||
import copy
|
||||
import difflib
|
||||
import functools
|
||||
import inspect
|
||||
import sys
|
||||
import warnings
|
||||
from collections import Counter, namedtuple
|
||||
@ -2038,16 +2037,6 @@ class Query(BaseExpression):
|
||||
group_by = list(self.select)
|
||||
if self.annotation_select:
|
||||
for alias, annotation in self.annotation_select.items():
|
||||
signature = inspect.signature(annotation.get_group_by_cols)
|
||||
if 'alias' not in signature.parameters:
|
||||
annotation_class = annotation.__class__
|
||||
msg = (
|
||||
'`alias=None` must be added to the signature of '
|
||||
'%s.%s.get_group_by_cols().'
|
||||
) % (annotation_class.__module__, annotation_class.__qualname__)
|
||||
warnings.warn(msg, category=RemovedInDjango40Warning)
|
||||
group_by_cols = annotation.get_group_by_cols()
|
||||
else:
|
||||
if not allow_aliases or alias in column_names:
|
||||
alias = None
|
||||
group_by_cols = annotation.get_group_by_cols(alias=alias)
|
||||
|
@ -257,6 +257,9 @@ to remove usage of these features.
|
||||
* ``django.views.i18n.set_language()`` doesn't set the user language in
|
||||
``request.session`` (key ``_language``).
|
||||
|
||||
* ``alias=None`` is required in the signature of
|
||||
``django.db.models.Expression.get_group_by_cols()`` subclasses.
|
||||
|
||||
See :ref:`deprecated-features-3.1` for details on these changes, including how
|
||||
to remove usage of these features.
|
||||
|
||||
|
@ -1,24 +0,0 @@
|
||||
from django.db.models import Count, Func
|
||||
from django.test import SimpleTestCase
|
||||
from django.utils.deprecation import RemovedInDjango40Warning
|
||||
|
||||
from .models import Employee
|
||||
|
||||
|
||||
class MissingAliasFunc(Func):
|
||||
template = '1'
|
||||
|
||||
def get_group_by_cols(self):
|
||||
return []
|
||||
|
||||
|
||||
class GetGroupByColsTest(SimpleTestCase):
|
||||
def test_missing_alias(self):
|
||||
msg = (
|
||||
'`alias=None` must be added to the signature of '
|
||||
'expressions.test_deprecation.MissingAliasFunc.get_group_by_cols().'
|
||||
)
|
||||
with self.assertRaisesMessage(RemovedInDjango40Warning, msg):
|
||||
Employee.objects.values(
|
||||
one=MissingAliasFunc(),
|
||||
).annotate(cnt=Count('company_ceo_set'))
|
Loading…
Reference in New Issue
Block a user