diff --git a/django/db/models/sql/query.py b/django/db/models/sql/query.py index a39430b28d..b524e8859f 100644 --- a/django/db/models/sql/query.py +++ b/django/db/models/sql/query.py @@ -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,19 +2037,9 @@ 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) + if not allow_aliases or alias in column_names: + alias = None + group_by_cols = annotation.get_group_by_cols(alias=alias) group_by.extend(group_by_cols) self.group_by = tuple(group_by) diff --git a/docs/releases/4.0.txt b/docs/releases/4.0.txt index 43e94a790b..339147201d 100644 --- a/docs/releases/4.0.txt +++ b/docs/releases/4.0.txt @@ -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. diff --git a/tests/expressions/test_deprecation.py b/tests/expressions/test_deprecation.py deleted file mode 100644 index cdb1e43af6..0000000000 --- a/tests/expressions/test_deprecation.py +++ /dev/null @@ -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'))