fix(starlette): Update test for Starlette 1.0 TemplateResponse API#5525
Conversation
…ette 1.0 Starlette 1.0.0rc1 removed the deprecated `TemplateResponse(name, context)` calling convention. The new API is `TemplateResponse(request, name, context)`. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Codecov Results 📊✅ 13 passed | Total: 13 | Pass Rate: 100% | Execution Time: 7.49s All tests are passing successfully. ✅ Patch coverage is 100.00%. Project has 13729 uncovered lines. Files with missing lines (180)
Generated by Codecov Action |
Semver Impact of This PR🟢 Patch (bug fixes) 📋 Changelog PreviewThis is how your changes will appear in the changelog. Bug Fixes 🐛Openai
Other
Documentation 📚
Internal Changes 🔧Agents
Openai Agents
Other
🤖 This preview updates automatically when you update the PR. |
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
Bugbot Autofix is OFF. To automatically fix reported issues with Cloud Agents, enable Autofix in the Cursor dashboard.
| if STARLETTE_VERSION >= (1,): | ||
| return templates.TemplateResponse( | ||
| request, "trace_meta.html", template_context | ||
| ) |
There was a problem hiding this comment.
Redundant request in template context for Starlette 1.0
Low Severity
The template_context dict includes "request": request on line 144, which is redundant when using the Starlette 1.0+ API that passes request as a separate parameter on line 149. Starlette automatically injects request into the context when passed as a parameter, and best practice is to avoid including it in the context dict to prevent potential conflicts. The context should only contain {"msg": "Hello Template World!"} for the new API branch.


Summary
test_template_tracing_metafailure onstarlette==1.0.0rc1across all Python versions (3.10, 3.13, 3.14, 3.14t)Closes #5523
Analysis
Starlette 1.0.0rc1 removed the deprecated
TemplateResponse(name, context)calling convention (encode/starlette#3118, commit96479da). The new required signature isTemplateResponse(request, name, context).When the old-style call was made, the string template name was passed as the
requestparameter and the context dict asname, which then got used as part of a Jinja2 cache key tuple, causingTypeError: unhashable type: 'dict'.The fix branches on
STARLETTE_VERSION >= (1,)to use the new API for Starlette 1.0+ while keeping the old API for older versions.Test plan
tox -e py3.14-starlette-v1.0.0rc1— 71 passedtox -e py3.14-starlette-v0.52.1— 71 passed (no regression)🤖 Generated with Claude Code