fastapi - 💡(How to fix) Fix FastAPI + Starlette 1.0.0: Jinja2 TemplateResponse raises 'unhashable type: dict' [1 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
fastapi/fastapi#15197Fetched 2026-04-08 01:16:19
View on GitHub
Comments
0
Participants
1
Timeline
2
Reactions
0
Author
Participants
Timeline (top)
converted_to_discussion ×1locked ×1

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.

Error Message

TypeError: cannot use 'tuple' as a dict key (unhashable type: 'dict')

Root Cause

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.

Fix Action

Workaround

Pin starlette<1.0.0 in requirements.txt.

Code Example

TypeError: cannot use 'tuple' as a dict key (unhashable type: 'dict')
RAW_BUFFERClick to expand / collapse

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

  1. Install fastapi==0.135.1 with starlette==1.0.0
  2. Create a route that returns a Jinja2Templates.TemplateResponse
  3. 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.

extent analysis

Fix Plan

To fix the compatibility issue between FastAPI, Starlette

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

fastapi - 💡(How to fix) Fix FastAPI + Starlette 1.0.0: Jinja2 TemplateResponse raises 'unhashable type: dict' [1 participants]