Reputation: 90
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.
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/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
}
]
}
The debugger should stop at the breakpoint set in the management command for both configuration types.
"type": "debugpy"
, the breakpoint is not hit, and the command runs to completion without stopping."type": "python"
, the breakpoint is hit as expected, and I can step through the code..pyc
files and restarted VSCode"justMyCode": true
and "justMyCode": false
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!
Upvotes: 0
Views: 183
Reputation: 9209
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.
Upvotes: 0