X Tutup
Skip to content

Add debugger support for fastapi#11789

Merged
RayBB merged 4 commits intointernetarchive:masterfrom
cdrini:dev/fastapi-debugger
Feb 4, 2026
Merged

Add debugger support for fastapi#11789
RayBB merged 4 commits intointernetarchive:masterfrom
cdrini:dev/fastapi-debugger

Conversation

@cdrini
Copy link
Collaborator

@cdrini cdrini commented Jan 31, 2026

Add ability to attach a debugger. To do so:

  1. docker compose up -d as usual
  2. In VS code, choose "OL: Attach to FastAPI container" in the debug panel

And boom! You have a debugger.

Technical

Testing

Screenshot

Also enable the fastapi debug view on error:

image

Stakeholders

@RayBB

Copilot AI review requested due to automatic review settings January 31, 2026 02:00
@github-project-automation github-project-automation bot moved this to Waiting Review/Merge from Staff in Ray's Project Jan 31, 2026
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines +123 to +126
debugpy.listen(('0.0.0.0', 3000)) # noqa: T100
logger.info(
"🐛 Debugger ready to attach from VS Code! Select 'OL: Attach to FastAPI container'."
)
Copy link

Copilot AI Feb 3, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
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'."
)

Copilot uses AI. Check for mistakes.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Copy link
Collaborator

@RayBB RayBB left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested locally connecting, works great.

Only thing I'd say is lets add info about this to the docs, maybe a small gif.

@RayBB RayBB merged commit 6d86d37 into internetarchive:master Feb 4, 2026
5 checks passed
@github-project-automation github-project-automation bot moved this from Waiting Review/Merge from Staff to Done in Ray's Project Feb 4, 2026
lokesh pushed a commit to lokesh/openlibrary that referenced this pull request Feb 4, 2026
bhardwajparth51 added a commit to bhardwajparth51/openlibrary that referenced this pull request Feb 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

3 participants

X Tutup