debugpy, primarily designed for VSCode but compatible with other debugpy-compatible IDEs.
Setup Debugging Environment
Use Local Development Override
Ensure your.env file includes the local development override:
docker-compose.override.local.yml file configures debugpy for both app and worker_wrapper services.
Debugpy Ports
Default debugpy ports (configured in.env):
- app:
5678(mapped toDEBUG_APP_DEBUGPY_PORT) - worker_wrapper:
5679(mapped toDEBUG_WORKER_WRAPPER_DEBUGPY_PORT) - qgis:
5680(mapped toDEBUG_QGIS_DEBUGPY_PORT, optional)
VSCode Setup
Launch Configuration
The repository includes.vscode/launch.json with three debug configurations:
1. Attach to App
2. Attach to Worker Wrapper
3. Attach to QGIS Worker
Start Debugging
- Start the services:
- In VSCode, press
F5or go to Run and Debug panel - Select the appropriate configuration (app or worker_wrapper)
- Click the green play button or press
F5
Debugging Modes
Mode 1: Always-On Debugging (Default)
By default,debugpy is running in the background, ready to accept connections. This mode doesn’t pause execution.
- Set breakpoints in VSCode
- Attach the debugger with
F5 - Trigger the code path (make an API request, run a job, etc.)
- Debugger will pause at breakpoints
Mode 2: Wait for Debugger
To pause execution before any code runs, add this snippet to your code:docker-app/qfieldcloud/wsgi.pyfor app startupdocker-app/worker_wrapper/wrapper.pyfor worker startup- Any management command or view
Mode 3: Debug Specific Commands
Prefix commands with the debugpy invocation:Mode 4: Persistent Wait-for-Client
Modifydocker-compose.override.local.yml to always wait:
Debug Vendor Modules
To debug code in third-party packages (installed viapip):
1. Copy Site Packages
Copy the Python packages from the container to your host:2. Update Path Mappings
In.vscode/launch.json, uncomment the vendor path mapping:
3. Re-copy After Dependency Changes
Important: Re-run the copy command wheneverrequirements*.txt files change:
Debugging QGIS Workers
Debugging QGIS workers is more complex because they run in separate Docker containers.Set DEBUG_QGIS_DEBUGPY_PORT
In.env, set the QGIS debug port:
Mount Local Code
To debug your local QGIS worker code, set:docker-qgis/qfc_workerdocker-qgis/entrypoint.pydocker-qgis/libqfieldsync(if present)docker-qgis/qfieldcloud-sdk-python(if present)
Attach to QGIS Worker
- Trigger a job that spawns a QGIS worker
- The worker will pause waiting for debugger
- In VSCode, select QFieldCloud Debug (Attach) - qgis
- Press
F5 - Set breakpoints in
docker-qgis/qfc_worker/*.py
Debugging Tips
Set Breakpoints
Click in the gutter (left of line numbers) or pressF9.
Step Through Code
F10: Step over (execute current line)F11: Step into (enter function)Shift+F11: Step out (exit function)F5: Continue execution
Inspect Variables
Hover over variables or use the Variables panel in VSCode.Evaluate Expressions
Use the Debug Console to run Python expressions:Conditional Breakpoints
Right-click a breakpoint and set a condition:Log Points
Add a log point instead of a breakpoint to log without pausing: Right-click in the gutter → Add LogpointCommon Issues
Debugger Won’t Attach
Problem: “Timed out waiting for debugger connection” Solutions:- Check that the service is running:
- Verify the port mapping:
- Check debugpy is listening:
- Restart the service:
Breakpoints Not Hitting
Problem: Debugger attached but breakpoints don’t trigger. Solutions:-
Check path mappings: Ensure
localRootandremoteRootmatch. -
Verify file is executed: Add a
print()statement to confirm. - Check source code is mounted:
- Reload the module: Restart the service after code changes:
Container Exits Immediately
Problem: Container exits when using--wait-for-client.
Solution: Attach the debugger quickly, or increase the timeout.
Alternatively, add a long sleep:
Performance Issues
Problem: Debugger is slow or unresponsive. Solutions:- Disable
justMyCode: falseif not needed - Reduce log verbosity in
settings.py - Use conditional breakpoints to reduce hits
- Restart the container
Debugging Tests
To debug a test:Django Debug Toolbar
For web-based debugging, Django Debug Toolbar is enabled in development. Access: Visit any page athttps://localhost and look for the debug toolbar on the right side.
Features:
- SQL queries and performance
- Template rendering time
- Cache hits/misses
- Request headers and session data
settings.py:707-709:
Logs for Debugging
View Logs
Structured JSON Logs
QFieldCloud outputs JSON logs. To view them formatted:Nginx Logs
For detailed nginx logs:Next Steps
- Testing - Write and run tests
- Contributing - Submit your changes
- Architecture - Understand the codebase