[Django] #36712: Deferred Annotations on Template Tags lead to TypeError with Python 3.14

10 views
Skip to first unread message

Django

unread,
Nov 6, 2025, 3:28:04 AM (5 days ago) Nov 6
to django-...@googlegroups.com
#36712: Deferred Annotations on Template Tags lead to TypeError with Python 3.14
-------------------------------------+-------------------------------------
Reporter: Patrick Rauscher | Type:
| Uncategorized
Status: new | Component:
| Uncategorized
Version: 5.2 | Severity: Normal
Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Similar to #36696 (which covered mainly Signals) this covers templatetags,
where issues may happen when using SafeText:

{{{
from typing import TYPE_CHECKING

from django import template
from django.utils.html import escape

if TYPE_CHECKING:
from django.utils.safestring import SafeText


register = template.Library()

@register.filter("example")
def example_filter(value: str) -> SafeText:
return escape(value)
}}}

When using the templatetag, `django/template/base.py` line 763 (in django
5.2.8) will call `inspect.getfullargspec` for the filter, leading to a
NameError which gets translated by inspect to a `TypeError: unsupported
callable`. After searching a bit through the code this may also happen
with views, as several parts of django use inspect directly for different
checks (e.g. for templatetags it is used to check the number of
arguments).

Not sure if this is a bug in python or django yet. One solution in django
would be to replace direct calls to `inspect.signature` or
`inspect.getfullargspec` (which uses `inspect.signature` internally
according to python docs, but does not allow to specify an
`annotation_format`.
--
Ticket URL: <https://code.djangoproject.com/ticket/36712>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Nov 6, 2025, 3:53:09 AM (5 days ago) Nov 6
to django-...@googlegroups.com
#36712: Deferred Annotations on Template Tags lead to TypeError with Python 3.14
-------------------------------------+-------------------------------------
Reporter: Patrick Rauscher | Owner: Augusto
| Pontes
Type: Uncategorized | Status: assigned
Component: Uncategorized | Version: 5.2
Severity: Normal | Resolution:
Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Augusto Pontes):

* owner: (none) => Augusto Pontes
* status: new => assigned

--
Ticket URL: <https://code.djangoproject.com/ticket/36712#comment:1>

Django

unread,
Nov 6, 2025, 10:12:01 AM (5 days ago) Nov 6
to django-...@googlegroups.com
#36712: Deferred Annotations on Template Tags lead to TypeError with Python 3.14
-------------------------------------+-------------------------------------
Reporter: Patrick Rauscher | Owner: Augusto
| Pontes
Type: Bug | Status: assigned
Component: Template system | Version: 5.2
Severity: Release blocker | Resolution:
Keywords: typing, inspect, | Triage Stage: Accepted
deferred annotations |
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Jacob Walls):

* component: Uncategorized => Template system
* keywords: => typing, inspect, deferred annotations
* severity: Normal => Release blocker
* stage: Unreviewed => Accepted
* type: Uncategorized => Bug

Comment:

Thanks for the report. We should migrate away from
[https://docs.python.org/3/library/inspect.html#inspect.getfullargspec
getfullargspec()] anyway:

> Note that signature() and Signature Object provide the recommended API
for callable introspection, and support additional behaviours (like
positional-only arguments) that are sometimes encountered in extension
module APIs. This function is retained primarily for use in code that
needs to maintain compatibility with the Python 2 inspect module API.

See also this [https://github.com/python/cpython/issues/108901 deprecation
proposal].
--
Ticket URL: <https://code.djangoproject.com/ticket/36712#comment:2>

Django

unread,
Nov 8, 2025, 5:29:04 AM (3 days ago) Nov 8
to django-...@googlegroups.com
#36712: Deferred Annotations on Template Tags lead to TypeError with Python 3.14
-------------------------------------+-------------------------------------
Reporter: Patrick Rauscher | Owner: Augusto
| Pontes
Type: Bug | Status: assigned
Component: Template system | Version: 5.2
Severity: Release blocker | Resolution:
Keywords: typing, inspect, | Triage Stage: Accepted
deferred annotations |
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Comment (by Augusto Pontes):

Hi patrick, after some looking into the problem, it seems that this more a
python problem instead of a django problem, because i tested on these
versions: 3.12.3, 3.13.2, and the TypeError didnt raised, only at the
version 3.14 as you tested, im studying other alternatives to solve this
specific problem, depending on my progress, i will open a PR to give a
suggestion
--
Ticket URL: <https://code.djangoproject.com/ticket/36712#comment:3>

Django

unread,
Nov 8, 2025, 6:39:55 AM (3 days ago) Nov 8
to django-...@googlegroups.com
#36712: Deferred Annotations on Template Tags lead to TypeError with Python 3.14
-------------------------------------+-------------------------------------
Reporter: Patrick Rauscher | Owner: Augusto
| Pontes
Type: Bug | Status: assigned
Component: Template system | Version: 5.2
Severity: Release blocker | Resolution:
Keywords: typing, inspect, | Triage Stage: Accepted
deferred annotations |
Has patch: 0 | Needs documentation: 0
Needs tests: 1 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Augusto Pontes):

* needs_tests: 0 => 1

--
Ticket URL: <https://code.djangoproject.com/ticket/36712#comment:4>

Django

unread,
Nov 8, 2025, 7:03:12 AM (3 days ago) Nov 8
to django-...@googlegroups.com
#36712: Deferred Annotations on Template Tags lead to TypeError with Python 3.14
-------------------------------------+-------------------------------------
Reporter: Patrick Rauscher | Owner: Augusto
| Pontes
Type: Bug | Status: assigned
Component: Template system | Version: 5.2
Severity: Release blocker | Resolution:
Keywords: typing, inspect, | Triage Stage: Accepted
deferred annotations |
Has patch: 0 | Needs documentation: 0
Needs tests: 1 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Comment (by Augusto Pontes):

https://github.com/django/django/pull/20069
--
Ticket URL: <https://code.djangoproject.com/ticket/36712#comment:5>

Django

unread,
9:13 AM (1 hour ago) 9:13 AM
to django-...@googlegroups.com
#36712: Deferred Annotations on Template Tags lead to TypeError with Python 3.14
-------------------------------------+-------------------------------------
Reporter: Patrick Rauscher | Owner: Augusto
| Pontes
Type: Bug | Status: assigned
Component: Template system | Version: 5.2
Severity: Release blocker | Resolution:
Keywords: typing, inspect, | Triage Stage: Accepted
deferred annotations |
Has patch: 1 | Needs documentation: 0
Needs tests: 1 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Augusto Pontes):

* has_patch: 0 => 1

--
Ticket URL: <https://code.djangoproject.com/ticket/36712#comment:6>
Reply all
Reply to author
Forward
0 new messages