debug-flask_skill
6
GitHub Stars
1
Bundled Files
2 months ago
Catalog Refreshed
4 months ago
First Indexed
Readme & install
Copy the install command, review bundled files from the catalogue, and read any extended description pulled from the listing source.
Installation
Preview and clipboard use veilstrat where the catalogue uses aiagentskills.
npx veilstrat add skill snakeo/claude-debug-and-refactor-skills-plugin --skill debug-flask- SKILL.md16.8 KB
Overview
This skill systematically debugs Flask applications using a four-phase methodology and Flask-specific tools. It targets routing, template rendering, application/request context issues, SQLAlchemy session problems, blueprint registration, and circular imports. The goal is fast, repeatable diagnosis and safe fixes with minimal changes.
How this skill works
The skill inspects error patterns and run-time state, collects contextual logs and route maps, and guides interactive investigation via the Werkzeug debugger, Flask shell, pdb, and Flask-DebugToolbar. It prescribes targeted tests and configuration checks, then validates fixes with unit or integration tests and test-suite runs. Concrete code snippets and commands illustrate each step.
When to use it
- When you encounter 404/405 routing or endpoint mismatches
- When templates raise TemplateNotFound, UndefinedError, or syntax errors
- When you see RuntimeError about working outside application/request context
- When SQLAlchemy raises DetachedInstanceError or connection pool errors
- When blueprint registration fails or circular imports block app startup
Best practices
- Reproduce the error with a minimal test case before changing code
- Enable debug tools only in development; never run Werkzeug debugger in production
- Log request and response details and enable SQL query logging in dev
- Use flask shell and app.url_map to confirm routes and blueprint registration
- Manage SQLAlchemy sessions explicitly and close/remove sessions in teardown
Example use cases
- Fix a 404 caused by a blueprint not registered due to import ordering
- Resolve TemplateNotFound by verifying template folder configuration and blueprint template paths
- Diagnose DetachedInstanceError by inspecting session scope in tests and background tasks
- Track down 500 errors using the Werkzeug interactive traceback and in-code breakpoints
- Spot N+1 SQLAlchemy queries using query logging or Flask-DebugToolbar panels
FAQ
No. The Werkzeug debugger allows arbitrary code execution from the browser and must never be enabled in production.
How do I debug lazy-loaded relationships that fail after a request?
Either eager-load the relationship (e.g., joined loading), ensure the session is open when accessing it, or serialize needed fields inside the request context before returning the response.