Skip to content

Fix route discovery on starlette < 0.20.1#604

Merged
hansott merged 6 commits intomainfrom
fix-route-discovery-old-starlette
Apr 9, 2026
Merged

Fix route discovery on starlette < 0.20.1#604
hansott merged 6 commits intomainfrom
fix-route-discovery-old-starlette

Conversation

@hansott
Copy link
Copy Markdown
Member

@hansott hansott commented Apr 7, 2026

starlette._utils.is_async_callable was introduced in 0.20.1. On older versions (e.g. 0.16.0 used by FastAPI 0.70.0) the ImportError caused an early return, skipping the post_response handler entirely. This meant routes were never recorded in heartbeats.

Fall back to inspect.iscoroutinefunction when _utils is unavailable.

Summary by Aikido

Security Issues: 0 Quality Issues: 0 Resolved Issues: 0

⚡ Enhancements

  • Added version_requirement to Starlette on_import hooks to enforce minimum
  • Added fastapi-postgres-uvicorn-old to CI end-to-end test matrix workflow

🐛 Bugfixes

  • Fixed route discovery on older Starlette by falling back to inspect.iscoroutinefunction

More info

@hansott hansott marked this pull request as draft April 7, 2026 13:47
@tomaisthorpe tomaisthorpe force-pushed the fix-route-discovery-old-starlette branch from 5378e64 to 98b0f77 Compare April 8, 2026 17:50
@hansott hansott marked this pull request as ready for review April 8, 2026 22:32
hansott added 6 commits April 9, 2026 10:54
Pins FastAPI 0.70.0 (starlette 0.16.0) to reproduce and verify
route discovery on older starlette versions.
starlette._utils.is_async_callable was introduced in 0.20.1. On older
versions (e.g. 0.16.0 used by FastAPI 0.70.0) the ImportError caused
an early return, skipping the post_response handler entirely. This
meant routes were never recorded in heartbeats.

Fall back to inspect.iscoroutinefunction when _utils is unavailable.
Document supported versions in README (starlette ^0.16,
FastAPI ^0.70) and enforce via version_requirement on the
on_import hooks.
Rename fastapi-old to fastapi-postgres-uvicorn-old to match the naming
convention. Replace the minimal shell-injection app with a full postgres
sample app identical to the other fastapi variants, including templates,
SQL injection e2e tests, and route discovery assertions. Fix port
conflict with django-asgi-uvicorn (8114 -> 8118).
@hansott hansott force-pushed the fix-route-discovery-old-starlette branch from a8a587a to 482736f Compare April 9, 2026 09:40
@hansott hansott merged commit 38f3aec into main Apr 9, 2026
89 of 92 checks passed
@hansott hansott deleted the fix-route-discovery-old-starlette branch April 9, 2026 12:36
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.

2 participants