You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Cached routes crash under Starlette's TestClient when the response is a template #92
Hi! I've been using fastapi-redis-sdk 0.9.1 with route caching, and pages rendered with Jinja templates fail under Starlette's TestClient. The test client reports two response starts for the same request, and the page comes back as a 500.
From what I can tell, the cache middleware assumes every message other than the body arrives after http.response.start. Starlette's TemplateResponse sends an http.response.debug message before the start whenever the server advertises that extension, and TestClient does. The middleware treats that debug message as "flush the buffered start now", but nothing has been buffered yet. So the client gets a start it shouldn't, and then the real one.
It doesn't happen with servers that don't advertise the debug extension (Granian, in our case), so it mostly bites in tests.
A fix could be to pass any message that arrives before http.response.start straight through, without flushing anything. We work around it for now with a small middleware that drops the debug messages before they reach the cache.
Happy to send a PR if that helps. Thanks for the library!
Opened #93 with a fix. One correction to my report: the crash happens on uncached template routes. Cached ones don't crash, but they lose their headers and never get stored.
Activity
tishun commentedon Oct 24, 2026
Thanks for the bug report!
All contributions are very welcome, but if you do not have the time the team will address it the moment we have some time.
davidpoblador commentedon Oct 25, 2026
Opened #93 with a fix. One correction to my report: the crash happens on uncached template routes. Cached ones don't crash, but they lose their headers and never get stored.
fix: forward http.response.debug without turning off caching
fix: forward messages sent before the response start in the cache mid…