Description
After upgrading to Starlette 1.0.0, FastAPI applications using Jinja2 templates fail with:
TypeError: cannot use 'tuple' as a dict key (unhashable type: 'dict')
at jinja2/utils.py, line 515.
Environment
- FastAPI 0.135.1
- Starlette 1.0.0
- Jinja2 3.1.6
- Tested on Python 3.12 and 3.14 (issue reproduced on both)
Steps to reproduce
- Install
fastapi==0.135.1 with starlette==1.0.0
- Create a route that returns a
Jinja2Templates.TemplateResponse
- Any template render raises the error above
Workaround
Pin starlette<1.0.0 in requirements.txt.
Notes
This appears to be related to breaking changes in Starlette 1.0.0's TemplateResponse signature. FastAPI may need to update how it passes context to Jinja2 templates for Starlette 1.0.0 compatibility.
Detected in production during a routine deployment where pip resolved Starlette 1.0.0 instead of 0.52.x.
Description
After upgrading to Starlette 1.0.0, FastAPI applications using Jinja2 templates fail with:
at
jinja2/utils.py, line 515.Environment
Steps to reproduce
fastapi==0.135.1withstarlette==1.0.0Jinja2Templates.TemplateResponseWorkaround
Pin
starlette<1.0.0inrequirements.txt.Notes
This appears to be related to breaking changes in Starlette 1.0.0's
TemplateResponsesignature. FastAPI may need to update how it passes context to Jinja2 templates for Starlette 1.0.0 compatibility.Detected in production during a routine deployment where pip resolved Starlette 1.0.0 instead of 0.52.x.