Skip to content

FastAPI + Starlette 1.0.0: Jinja2 TemplateResponse raises 'unhashable type: dict' #15197

@boluda

Description

@boluda

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions