Add debugger support for fastapi#11789
Conversation
There was a problem hiding this comment.
Pull request overview
Adds local-development debugger attach support for the FastAPI container (debugpy), with Docker + VS Code configuration to expose and attach to the debug port.
Changes:
- Adds a FastAPI admin route to start/wait for a debugpy debugger attachment.
- Registers the new dev router in the ASGI app.
- Updates Docker Compose and VS Code launch configs to expose and attach to the FastAPI debug port (and adjusts worker count).
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 7 comments.
Show a summary per file
| File | Description |
|---|---|
| openlibrary/fastapi/dev.py | New FastAPI route for triggering debugpy listen/attach behavior. |
| openlibrary/asgi_app.py | Includes the new dev router in the FastAPI app. |
| compose.yaml | Adjusts FastAPI Gunicorn default worker count. |
| compose.override.yaml | Publishes the FastAPI debugger port to the host for local dev. |
| .vscode/launch.json | Adds VS Code debugpy attach configuration for the FastAPI container and renames the web attach config. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| debugpy.listen(('0.0.0.0', 3000)) # noqa: T100 | ||
| logger.info( | ||
| "🐛 Debugger ready to attach from VS Code! Select 'OL: Attach to FastAPI container'." | ||
| ) |
There was a problem hiding this comment.
debugpy.listen() will raise (e.g., if the port is already bound during gunicorn reloads / rapid restarts) and would currently crash app startup in LOCAL_DEV. Consider making this setup resilient by catching OSError/RuntimeError and logging a warning (or skipping if already initialized) so the FastAPI container can still boot even when the debugger port can’t be acquired.
| debugpy.listen(('0.0.0.0', 3000)) # noqa: T100 | |
| logger.info( | |
| "🐛 Debugger ready to attach from VS Code! Select 'OL: Attach to FastAPI container'." | |
| ) | |
| try: | |
| debugpy.listen(('0.0.0.0', 3000)) # noqa: T100 | |
| except (OSError, RuntimeError) as exc: | |
| logger.warning( | |
| "Failed to start debugpy listener on 0.0.0.0:3000; continuing without debugger: %s", | |
| exc, | |
| ) | |
| else: | |
| logger.info( | |
| "🐛 Debugger ready to attach from VS Code! Select 'OL: Attach to FastAPI container'." | |
| ) |
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
RayBB
left a comment
There was a problem hiding this comment.
Tested locally connecting, works great.
Only thing I'd say is lets add info about this to the docs, maybe a small gif.
…gger Add debugger support for fastapi
…gger Add debugger support for fastapi
Add ability to attach a debugger. To do so:
docker compose up -das usualAnd boom! You have a debugger.
Technical
Testing
Screenshot
Also enable the fastapi debug view on error:
Stakeholders
@RayBB