Skip to content

Fix Starlette 1.0.0 TemplateResponse API compatibility#84

Open
vdaluz wants to merge 1 commit intosam1am:mainfrom
vdaluz:fix/starlette-1.0-compatibility
Open

Fix Starlette 1.0.0 TemplateResponse API compatibility#84
vdaluz wants to merge 1 commit intosam1am:mainfrom
vdaluz:fix/starlette-1.0-compatibility

Conversation

@vdaluz
Copy link
Copy Markdown

@vdaluz vdaluz commented Apr 16, 2026

Background

requirements.txt specifies fastapi and uvicorn without version pins. FastAPI bundles Starlette as a dependency, and Starlette 1.0.0 (released September 2024) introduced a breaking change to TemplateResponse. New installs now resolve to Starlette 1.0.0+ and the app might be broken out of the box with a 500 on every HTML page.

What breaks

The old TemplateResponse API passed the template name first and embedded request in the context dict:

# Old — broken with Starlette 1.0.0+
TemplateResponse("name.html", {"request": request, ...})

Starlette 1.0.0 changed the signature — request is now the first positional argument and is no longer part of the context dict:

# New — correct for Starlette 1.0.0+
TemplateResponse(request, "name.html", {...})

The old style raises TypeError: unhashable type: 'dict' at runtime because Jinja2's template LRU cache receives the context dict where it expects the template name string.

Fix

Updates all 14 TemplateResponse calls across app_auth.py, library.py, discover.py, collections.py, and settings.py to use the new API.

Starlette 1.0.0 changed the TemplateResponse calling convention.
The old positional API passed the template name first and a dict
containing the request object:

    TemplateResponse("name.html", {"request": request, ...})

The new API takes the request as the first argument and removes it
from the context dict:

    TemplateResponse(request, "name.html", {...})

The old style causes a TypeError at runtime with Starlette 1.0.0+,
breaking every page that renders an HTML response. Updated all 14
TemplateResponse calls across the five route files.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant