diff options
| author | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2021-01-07 07:55:06 +0100 |
|---|---|---|
| committer | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2021-01-14 17:50:04 +0100 |
| commit | 5e33ec80d153416d3693e89138ed21decf042672 (patch) | |
| tree | 57d5feea09185981f50bbb27fd503b03ebc41106 | |
| parent | d134b0b93ee10a2128c595997cbc6022c4a982f7 (diff) | |
Refs #30158 -- Made alias argument required in signature of Expression.get_group_by_cols() subclasses.
Per deprecation timeline.
| -rw-r--r-- | django/db/models/sql/query.py | 17 | ||||
| -rw-r--r-- | docs/releases/4.0.txt | 3 | ||||
| -rw-r--r-- | tests/expressions/test_deprecation.py | 24 |
3 files changed, 6 insertions, 38 deletions
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')) |
