VSCode Django Debugging: Breakpoints not working with 'debugpy', but work with 'python' type
When trying to debug a Django management command in VSCode, I encountered an issue where breakpoints were not being hit when using the 'debugpy' configuration type. However, when I switched to the 'python' configuration type, the breakpoints started working as expected.
Steps to Reproduce
- Create a new Django project and app
- Create a simple management command
- Set up VSCode debug configuration
- Set breakpoints in the management command
- Try to debug the management command
Django Management Command (myapp/management/commands/hello_world.py
):
from django.core.management.base import BaseCommand
class Command(BaseCommand):
help = 'Prints Hello, World!'
def handle(self, *args, **options):
message = "Hello, World!" # Set a breakpoint on this line
self.stdout.write(message)
VSCode Debug Configuration (.vscode/launch.json
):
{
"version": "0.2.0",
"configurations": [
{
"name": "Django Command (debugpy)",
"type": "debugpy",
"request": "launch",
"program": "${workspaceFolder}/manage.py",
"args": [
"hello_world"
],
"django": true,
"justMyCode": false
},
{
"name": "Django Command (python)",
"type": "python",
"request": "launch",
"program": "${workspaceFolder}/manage.py",
"args": [
"hello_world"
],
"django": true,
"justMyCode": false
}
]
}
Expected Behavior
The debugger should stop at the breakpoint set in the management command for both configuration types.
Actual Behavior
- With
"type": "debugpy"
, the breakpoint is not hit, and the command runs to completion without stopping. - With
"type": "python"
, the breakpoint is hit as expected, and I can step through the code.
Attempted Solutions
- Cleared all
.pyc
files and restarted VSCode - Ensured the correct Python interpreter is selected in VSCode
- Verified that Django's DEBUG setting is True
- Tried with both
"justMyCode": true
and"justMyCode": false
Question
Why does the debugger behave differently with 'debugpy' and 'python' configuration types? Is this a known issue, and is there a way to make 'debugpy' work correctly with Django management commands?
Any insights or solutions would be greatly appreciated!
Ensure that you've installed or updated the Python extension and Python Debugger extension.
Debugpy has been removed from the Python extension in favor of the Python Debugger extension in May 2024 release.