diff --git a/django/db/models/sql/query.py b/django/db/models/sql/query.py index 988689485c..d002698c63 100644 --- a/django/db/models/sql/query.py +++ b/django/db/models/sql/query.py @@ -1916,9 +1916,8 @@ class Query(BaseExpression): group_by = list(self.select) if self.annotation_select: for alias, annotation in self.annotation_select.items(): - try: - inspect.getcallargs(annotation.get_group_by_cols, alias=alias) - except TypeError: + 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 ' diff --git a/django/template/base.py b/django/template/base.py index ce33051312..7efc45356c 100644 --- a/django/template/base.py +++ b/django/template/base.py @@ -857,8 +857,9 @@ class Variable: try: # method call (assuming no args required) current = current() except TypeError: + signature = inspect.signature(current) try: - inspect.getcallargs(current) + signature.bind() except TypeError: # arguments *were* required current = context.template.engine.string_if_invalid # invalid method call else: