Skip to content

fix: update TemplateResponse calls for Starlette 1.0 compatibility#94

Open
ayazhankadessova wants to merge 1 commit intosugarlabs:mainfrom
ayazhankadessova:fix/starlette-template-response
Open

fix: update TemplateResponse calls for Starlette 1.0 compatibility#94
ayazhankadessova wants to merge 1 commit intosugarlabs:mainfrom
ayazhankadessova:fix/starlette-template-response

Conversation

@ayazhankadessova
Copy link
Copy Markdown

Problem

Every HTML page in Sugar-AI returns a 500 Internal Server Error when installed with current dependencies:

TypeError: unhashable type: 'dict'

This affects the welcome page (/), dashboard (/dashboard), admin panel (/admin), OAuth login (/oauth-login), admin login (/admin-login), and key request (/request-key) pages.

Root Cause

requirements.txt has unpinned fastapi, which now installs Starlette 1.0. Starlette 1.0 changed the TemplateResponse API — the request object is now a required first positional argument instead of being passed inside the context dict:

# Old (Starlette <1.0) — what the codebase currently uses
TemplateResponse("name.html", {"request": request, ...})

# New (Starlette 1.0+) — required signature
TemplateResponse(request, "name.html", context={...})

Steps to Reproduce

  1. Clone the repo
  2. pip install -r requirements.txt (installs FastAPI 0.135+ with Starlette 1.0)
  3. DEV_MODE=1 uvicorn main:app --host 0.0.0.0 --port 8000
  4. Visit http://localhost:8000/ → 500 error

Fix

Updated all 9 TemplateResponse calls across 4 route modules to use the Starlette 1.0 API.

Files Changed

  • app/routes/web.py — welcome page and dashboard
  • app/routes/main.py — root welcome page
  • app/routes/admin.py — admin panel
  • app/routes/auth.py — OAuth login, admin login, key request pages

Testing

After the fix, all pages load correctly:

  • GET / — welcome page renders
  • GET /oauth-login — login page renders
  • GET /admin-login — admin login renders
  • GET /request-key — key request form renders
  • All API endpoints (/ask, /ask-llm, /ask-llm-prompted) are unaffected (JSON, no templates)

Starlette 1.0 (shipped with FastAPI 0.135+) changed the
TemplateResponse API. The request object is now a required first
positional argument instead of being passed inside the context dict.

Old: TemplateResponse("name.html", {"request": request, ...})
New: TemplateResponse(request, "name.html", context={...})

Without this fix, every HTML page returns a 500 error:
  TypeError: unhashable type: 'dict'

Updated all TemplateResponse calls across web, auth, admin, and
main route modules.
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