Skip to content
This repository has been archived by the owner on Aug 2, 2023. It is now read-only.

Breakpoints aren't being hit in local Django project #1794

Closed
j3lev opened this issue Sep 20, 2019 · 11 comments
Closed

Breakpoints aren't being hit in local Django project #1794

j3lev opened this issue Sep 20, 2019 · 11 comments

Comments

@j3lev
Copy link

j3lev commented Sep 20, 2019

Here is my launch.json

{
            "name": "Python: Django",
            "type": "python",
            "request": "launch",
            "port": 8001,
            "program": "${workspaceFolder}/manage.py",
            "console": "integratedTerminal",
            "args": [
                "httpsrunserver"
            ],
            "django": true,
            "pythonPath": "${workspaceFolder}/.venv/bin/python",
            "justMyCode": false
}

My debug log:

2019-9-20, 15:56:50.805 UTC
[15:56:50.805 UTC] Started @ Fri Sep 20 2019 11:56:50 GMT-0400 (Eastern Daylight Time)
[15:56:50.805 UTC] From Client:
[15:56:50.805 UTC] Content-Length: 313

{"command":"initialize","arguments":{"clientID":"vscode","clientName":"Visual Studio Code","adapterID":"python","pathFormat":"path","linesStartAt1":true,"columnsStartAt1":true,"supportsVariableType":true,"supportsVariablePaging":true,"supportsRunInTerminalRequest":true,"locale":"en-us"},"type":"request","seq":1}
[15:56:50.805 UTC] To Client:
[15:56:50.805 UTC] Content-Length: 761

{"seq":1,"type":"response","request_seq":1,"command":"initialize","success":true,"body":{"supportsExceptionInfoRequest":true,"supportsConfigurationDoneRequest":true,"supportsDelayedStackTraceLoading":true,"supportsConditionalBreakpoints":true,"supportsSetVariable":true,"supportsExceptionOptions":true,"supportsGotoTargetsRequest":true,"supportsEvaluateForHovers":true,"supportsModulesRequest":true,"supportsValueFormattingOptions":true,"supportsHitConditionalBreakpoints":true,"supportsSetExpression":true,"supportsLogPoints":true,"supportTerminateDebuggee":true,"supportsCompletionsRequest":true,"exceptionBreakpointFilters":[{"filter":"raised","label":"Raised Exceptions","default":false},{"filter":"uncaught","label":"Uncaught Exceptions","default":true}]}}
[15:56:50.805 UTC] From Client:
[15:56:50.805 UTC] Content-Length: 777

{"command":"launch","arguments":{"name":"Python: Django","type":"python","request":"launch","port":8001,"program":"/Users/joelevenson/Documents/my_project/manage.py","console":"integratedTerminal","args":["httpsrunserver"],"django":true,"pythonPath":"/Users/joelevenson/Documents/my_project/.venv/bin/python","logToFile":true,"cwd":"/Users/joelevenson/Documents/my_project","envFile":"/Users/joelevenson/Documents/my_project/.env","env":{"PYTHONIOENCODING":"UTF-8","PYTHONUNBUFFERED":"1"},"stopOnEntry":false,"showReturnValue":true,"internalConsoleOptions":"neverOpen","debugOptions":["ShowReturnValue","Django","RedirectOutput"],"justMyCode":true,"workspaceFolder":"/Users/joelevenson/Documents/my_project","__sessionId":"9ace3726-bb75-48d4-b434-d0772c681827"},"type":"request","seq":2}
[15:56:50.808 UTC] To Client:
[15:56:50.808 UTC] Content-Length: 514

{"command":"runInTerminal","arguments":{"kind":"integrated","title":"Python Debug Console","cwd":"/Users/joelevenson/Documents/my_project","args":["/Users/joelevenson/Documents/my_project/.venv/bin/python","/Users/joelevenson/.vscode/extensions/ms-python.python-2019.9.34911/pythonFiles/ptvsd_launcher.py","--default","--client","--host","localhost","--port","8001","/Users/joelevenson/Documents/my_project/manage.py","httpsrunserver"],"env":{"PYTHONIOENCODING":"UTF-8","PYTHONUNBUFFERED":"1"}},"type":"request","seq":2}
[15:56:51.343 UTC] From Client:
[15:56:51.343 UTC] Content-Length: 115

{"type":"response","seq":3,"command":"runInTerminal","request_seq":2,"success":true,"body":{"shellProcessId":8120}}
[15:56:52.473 UTC] To Client:
[15:56:52.473 UTC] Content-Length: 777


[15:56:52.473 UTC] To Client:
[15:56:52.473 UTC] {"command":"launch","arguments":{"name":"Python: Django","type":"python","request":"launch","port":8001,"program":"/Users/joelevenson/Documents/my_project/manage.py","console":"integratedTerminal","args":["httpsrunserver"],"django":true,"pythonPath":"/Users/joelevenson/Documents/my_project/.venv/bin/python","logToFile":true,"cwd":"/Users/joelevenson/Documents/my_project","envFile":"/Users/joelevenson/Documents/my_project/.env","env":{"PYTHONIOENCODING":"UTF-8","PYTHONUNBUFFERED":"1"},"stopOnEntry":false,"showReturnValue":true,"internalConsoleOptions":"neverOpen","debugOptions":["ShowReturnValue","Django","RedirectOutput"],"justMyCode":true,"workspaceFolder":"/Users/joelevenson/Documents/my_project","__sessionId":"9ace3726-bb75-48d4-b434-d0772c681827"},"type":"request","seq":2}
[15:56:52.473 UTC] To Client:
[15:56:52.473 UTC] Content-Length: 313


[15:56:52.473 UTC] To Client:
[15:56:52.473 UTC] {"command":"initialize","arguments":{"clientID":"vscode","clientName":"Visual Studio Code","adapterID":"python","pathFormat":"path","linesStartAt1":true,"columnsStartAt1":true,"supportsVariableType":true,"supportsVariablePaging":true,"supportsRunInTerminalRequest":true,"locale":"en-us"},"type":"request","seq":1}
[15:56:52.473 UTC] To Client:
[15:56:52.473 UTC] Content-Length: 130

{"body": {"category": "telemetry", "output": "ptvsd", "data": {"version": "4.3.2"}}, "type": "event", "event": "output", "seq": 0}
[15:56:52.475 UTC] To Client:
[15:56:52.475 UTC] Content-Length: 113

{"request_seq": 2, "body": {}, "seq": 1, "success": true, "command": "launch", "message": "", "type": "response"}
[15:56:52.475 UTC] To Client:
[15:56:52.475 UTC] Content-Length: 865

{"request_seq": 1, "body": {"supportsModulesRequest": true, "supportsConfigurationDoneRequest": true, "supportsDelayedStackTraceLoading": true, "supportsDebuggerProperties": true, "supportsEvaluateForHovers": true, "supportsSetExpression": true, "supportsExceptionOptions": true, "exceptionBreakpointFilters": [{"filter": "raised", "default": false, "label": "Raised Exceptions"}, {"filter": "uncaught", "default": true, "label": "Uncaught Exceptions"}], "supportsCompletionsRequest": true, "supportsExceptionInfoRequest": true, "supportsLogPoints": true, "supportsValueFormattingOptions": true, "supportsHitConditionalBreakpoints": true, "supportsSetVariable": true, "supportTerminateDebuggee": true, "supportsGotoTargetsRequest": true, "supportsConditionalBreakpoints": true}, "seq": 2, "success": true, "command": "initialize", "message": "", "type": "response"}Content-Length: 63


[15:56:52.475 UTC] To Client:
[15:56:52.475 UTC] {"body": {}, "type": "event", "event": "initialized", "seq": 3}
[15:56:52.477 UTC] To Client:
[15:56:52.477 UTC] Content-Length: 190


[15:56:52.477 UTC] To Client:
[15:56:52.477 UTC] {"body": {"isLocalProcess": true, "startMethod": "launch", "name": "/Users/joelevenson/Documents/my_project/manage.py", "systemProcessId": 8376}, "type": "event", "event": "process", "seq": 4}
[15:56:52.481 UTC] From Client:
[15:56:52.481 UTC] Content-Length: 234

{"command":"setBreakpoints","arguments":{"source":{"name":"api.py","path":"/Users/joelevenson/Documents/my_project/my_project/apps/my_app/api.py"},"lines":[202],"breakpoints":[{"line":202}],"sourceModified":false},"type":"request","seq":4}
[15:56:52.504 UTC] To Client:
[15:56:52.504 UTC] Content-Length: 284

{"request_seq": 4, "body": {"breakpoints": [{"source": {"path": "/Users/joelevenson/Documents/my_project/my_project/apps/my_app/api.py", "name": "api.py"}, "line": 202, "verified": true, "id": 0}]}, "seq": 5, "success": true, "command": "setBreakpoints", "message": "", "type": "response"}
[15:56:52.507 UTC] From Client:
[15:56:52.507 UTC] Content-Length: 99

{"command":"setExceptionBreakpoints","arguments":{"filters":["uncaught"]},"type":"request","seq":5}
[15:56:52.522 UTC] To Client:
[15:56:52.522 UTC] Content-Length: 130

{"request_seq": 5, "body": {}, "seq": 6, "success": true, "command": "setExceptionBreakpoints", "message": "", "type": "response"}
[15:56:52.525 UTC] From Client:
[15:56:52.525 UTC] Content-Length: 56

{"command":"configurationDone","type":"request","seq":6}
[15:56:52.526 UTC] To Client:
[15:56:52.526 UTC] Content-Length: 124

{"request_seq": 6, "body": {}, "seq": 7, "success": true, "command": "configurationDone", "message": "", "type": "response"}
[15:56:52.526 UTC] From Client:
[15:56:52.526 UTC] Content-Length: 46

{"command":"threads","type":"request","seq":7}
[15:56:52.530 UTC] To Client:
[15:56:52.530 UTC] Content-Length: 92

{"body": {"reason": "started", "threadId": 1}, "type": "event", "event": "thread", "seq": 8}
[15:56:52.531 UTC] To Client:
[15:56:52.531 UTC] Content-Length: 158


[15:56:52.531 UTC] To Client:
[15:56:52.531 UTC] {"request_seq": 7, "body": {"threads": [{"id": 1, "name": "MainThread"}]}, "seq": 9, "success": true, "command": "threads", "message": "", "type": "response"}
[15:56:52.633 UTC] From Client:
[15:56:52.633 UTC] Content-Length: 46

{"command":"threads","type":"request","seq":8}
[15:56:52.643 UTC] To Client:
[15:56:52.643 UTC] Content-Length: 159

{"request_seq": 8, "body": {"threads": [{"id": 1, "name": "MainThread"}]}, "seq": 10, "success": true, "command": "threads", "message": "", "type": "response"}
[15:58:04.986 UTC] Socket End
[15:58:04.986 UTC] check and shutdown
[15:58:04.986 UTC] shutdown
[15:58:04.986 UTC] Sending Terminated Event
[15:58:04.986 UTC] To Client:
[15:58:04.986 UTC] Content-Length: 45


[15:58:04.986 UTC] onEventTerminated
[15:58:04.986 UTC] To Client:
[15:58:04.986 UTC] {"seq":0,"type":"event","event":"terminated"}
[15:58:04.986 UTC] killing process
[15:58:04.990 UTC] From Client:
[15:58:04.991 UTC] Content-Length: 79

{"command":"disconnect","arguments":{"restart":false},"type":"request","seq":9}
[15:58:04.991 UTC] Socket Error
[15:58:04.991 UTC] check and shutdown
[15:58:05.088 UTC] Kill process now
[15:58:05.093 UTC] Shutting down debug session
[15:58:05.093 UTC] disposing

The debugger fires up the server ok and when I have breakpoints set on function definitions and start up code, the breakpoints work fine. Breakpoints that are set in endpoint handlers however, are not being called when the code itself is being executed. The httpsrunserver command executes python manage.py runserver_plus --noreload --nothreading --cert-file cert/server.crt --key-file cert/server.key.

OS: macOS Mojave
Python version: 2.7
Django version: 1.11

@karthiknadig
Copy link
Member

Can you use the env variables and generate the more detailed logs:

PTVSD_LOG_DIR=/logs
PYDEVD_DEBUG=True
PYDEVD_DEBUG_FILE=/logs/pydevd.log

Make sure that /logs/ dir exists. Remove any personal information from the logs before sharing. It should generate multiple log files.

@j3lev
Copy link
Author

j3lev commented Sep 20, 2019

pydevd: Use libraries filter: False

IDE_PROJECT_ROOTS []

LIBRARY_ROOTS ['/Users/joelevenson/Documents/my_project/.venv/lib/python2.7', '/Users/joelevenson/Documents/my_project/.venv/lib/python2.7/site-packages', '/usr/local/Cellar/python@2/2.7.16/Frameworks/Python.framework/Versions/2.7/lib/python2.7']

Process SetDebuggerPropertyRequest: {
    "arguments": {
        "dontTraceEndPatterns": [
            "ptvsd_launcher.py"
        ], 
        "dontTraceStartPatterns": [
            "/Users/joelevenson/.vscode/extensions/ms-python.python-2019.9.34911/pythonFiles/lib/python/ptvsd/"
        ], 
        "ideOS": "UNIX", 
        "multiThreadsSingleNotification": true, 
        "skipPrintBreakpointException": [
            "NameError"
        ], 
        "skipSuspendOnBreakpointException": [
            "BaseException"
        ]
    }, 
    "command": "setDebuggerProperty", 
    "seq": 1000000000, 
    "type": "request"
}

sending cmd -->           CMD_RETURN {"request_seq": 1000000000, "body": {}, "pydevd_cmd_id": 502, "success": true, "seq": 2, "command": "setDebuggerProperty", "type": "response"}

Process LaunchRequest: {
    "arguments": {
        "__sessionId": "5c3b261e-8783-445b-962b-ae6d74b54167", 
        "args": [
            "httpsrunserver"
        ], 
        "console": "integratedTerminal", 
        "cwd": "/Users/joelevenson/Documents/my_project", 
        "debugOptions": [
            "DebugStdLib", 
            "ShowReturnValue", 
            "Django", 
            "RedirectOutput"
        ], 
        "django": true, 
        "env": {
            "PTVSD_LOG_DIR": "/Users/joelevenson/Documents/my_project", 
            "PYDEVD_DEBUG": "True", 
            "PYDEVD_DEBUG_FILE": "/Users/joelevenson/Documents/my_project/debugger.log", 
            "PYTHONIOENCODING": "UTF-8", 
            "PYTHONUNBUFFERED": "1"
        }, 
        "envFile": "/Users/joelevenson/Documents/my_project/.env", 
        "internalConsoleOptions": "neverOpen", 
        "justMyCode": false, 
        "name": "Python: Django", 
        "port": 8001, 
        "program": "/Users/joelevenson/Documents/my_project/manage.py", 
        "pythonPath": "/Users/joelevenson/Documents/my_project/.venv/bin/python", 
        "request": "launch", 
        "showReturnValue": true, 
        "stopOnEntry": false, 
        "type": "python", 
        "workspaceFolder": "/Users/joelevenson/Documents/my_project"
    }, 
    "command": "launch", 
    "seq": 1000000001, 
    "type": "request"
}

sending cmd -->    CMD_PROCESS_EVENT {"body": {"isLocalProcess": true, "startMethod": "launch", "name": "/Users/joelevenson/Documents/my_project/manage.py", "systemProcessId": 18984}, "pydevd_cmd_id": 204, "type": "event", "event": "process", "seq": 4}

pydevd: Use libraries filter: False

Show return values: True
sending cmd -->           CMD_RETURN {"request_seq": 1000000001, "pydevd_cmd_id": 502, "success": true, "seq": 6, "command": "launch", "type": "response"}

Process SetBreakpointsRequest: {
    "arguments": {
        "breakpoints": [
            {
                "line": 202
            }
        ], 
        "lines": [
            202
        ], 
        "source": {
            "name": "api.py", 
            "path": "/Users/joelevenson/Documents/my_project/my_project/apps/my_app/api.py"
        }, 
        "sourceModified": false
    }, 
    "command": "setBreakpoints", 
    "seq": 1000000002, 
    "type": "request"
}

Request for breakpoint in: /Users/joelevenson/Documents/my_project/my_project/apps/my_app/api.py line: 202
Breakpoint (after path/source mapping) in: /Users/joelevenson/Documents/my_project/my_project/apps/my_app/api.py line: 202
Added breakpoint:/Users/joelevenson/Documents/my_project/my_project/apps/my_app/api.py - line:202 - func_name:None

sending cmd -->           CMD_RETURN {"request_seq": 1000000002, "body": {"breakpoints": [{"source": {"path": "/Users/joelevenson/Documents/my_project/my_project/apps/my_app/api.py", "name": "api.py"}, "line": 202, "verified": true, "id": 0}]}, "pydevd_cmd_id": 502, "success": true, "seq": 8, "command": "setBreakpoints", "type": "response"}

Process SetExceptionBreakpointsRequest: {
    "arguments": {
        "filters": [
            "uncaught"
        ]
    }, 
    "command": "setExceptionBreakpoints", 
    "seq": 1000000003, 
    "type": "request"
}

Exceptions to hook on terminate: {'BaseException': <_pydevd_bundle.pydevd_breakpoints.ExceptionBreakpoint object at 0x10af08d10>}.
sending cmd -->           CMD_RETURN {"request_seq": 1000000003, "pydevd_cmd_id": 502, "success": true, "seq": 10, "command": "setExceptionBreakpoints", "type": "response"}

Process ConfigurationDoneRequest: {
    "arguments": {}, 
    "command": "configurationDone", 
    "seq": 1000000004, 
    "type": "request"
}

sending cmd -->           CMD_RETURN {"request_seq": 1000000004, "pydevd_cmd_id": 502, "success": true, "seq": 12, "command": "configurationDone", "type": "response"}

Process ThreadsRequest: {
    "command": "threads", 
    "seq": 1000000005, 
    "type": "request"
}

sending cmd -->    CMD_THREAD_CREATE {"body": {"reason": "started", "threadId": 1}, "pydevd_cmd_id": 103, "type": "event", "event": "thread", "seq": 14}

sending cmd -->           CMD_RETURN {"request_seq": 1000000005, "body": {"threads": [{"id": 1, "name": "MainThread"}]}, "pydevd_cmd_id": 502, "success": true, "seq": 16, "command": "threads", "type": "response"}

SKIP set tracing of frame: /Users/joelevenson/.vscode/extensions/ms-python.python-2019.9.34911/pythonFiles/lib/python/ptvsd/_vendored/pydevd/pydevd.py - set_tracing_for_untraced_contexts
SKIP set tracing of frame: /Users/joelevenson/.vscode/extensions/ms-python.python-2019.9.34911/pythonFiles/lib/python/ptvsd/_vendored/pydevd/pydevd.py - _locked_settrace
SKIP set tracing of frame: /Users/joelevenson/.vscode/extensions/ms-python.python-2019.9.34911/pythonFiles/lib/python/ptvsd/_vendored/pydevd/pydevd.py - settrace
SKIP set tracing of frame: /Users/joelevenson/.vscode/extensions/ms-python.python-2019.9.34911/pythonFiles/lib/python/ptvsd/_remote.py - attach
SKIP set tracing of frame: /Users/joelevenson/.vscode/extensions/ms-python.python-2019.9.34911/pythonFiles/lib/python/ptvsd/__main__.py - setup_connection
SKIP set tracing of frame: /Users/joelevenson/.vscode/extensions/ms-python.python-2019.9.34911/pythonFiles/lib/python/ptvsd/__main__.py - run_file
SKIP set tracing of frame: /Users/joelevenson/.vscode/extensions/ms-python.python-2019.9.34911/pythonFiles/lib/python/ptvsd/__main__.py - main
SKIP set tracing of frame: /Users/joelevenson/.vscode/extensions/ms-python.python-2019.9.34911/pythonFiles/ptvsd_launcher.py - <module>
SKIP set tracing of frame: /Users/joelevenson/.vscode/extensions/ms-python.python-2019.9.34911/pythonFiles/lib/python/ptvsd/_vendored/pydevd/pydevd.py - settrace
SKIP set tracing of frame: /Users/joelevenson/.vscode/extensions/ms-python.python-2019.9.34911/pythonFiles/lib/python/ptvsd/_remote.py - attach
SKIP set tracing of frame: /Users/joelevenson/.vscode/extensions/ms-python.python-2019.9.34911/pythonFiles/lib/python/ptvsd/__main__.py - setup_connection
SKIP set tracing of frame: /Users/joelevenson/.vscode/extensions/ms-python.python-2019.9.34911/pythonFiles/lib/python/ptvsd/__main__.py - run_file
SKIP set tracing of frame: /Users/joelevenson/.vscode/extensions/ms-python.python-2019.9.34911/pythonFiles/lib/python/ptvsd/__main__.py - main
SKIP set tracing of frame: /Users/joelevenson/.vscode/extensions/ms-python.python-2019.9.34911/pythonFiles/ptvsd_launcher.py - <module>
Process ThreadsRequest: {
    "command": "threads", 
    "seq": 1000000006, 
    "type": "request"
}

sending cmd -->           CMD_RETURN {"request_seq": 1000000006, "body": {"threads": [{"id": 1, "name": "MainThread"}]}, "pydevd_cmd_id": 502, "success": true, "seq": 18, "command": "threads", "type": "response"}


@karthiknadig
Copy link
Member

@fabioz Can you see anything odd with the logs?

@josephlevenson Can you share your project if possible or a minimal repro?

@j3lev
Copy link
Author

j3lev commented Sep 20, 2019

Unfortunately I can't share my project, i'll try and get a minimal repro

@j3lev
Copy link
Author

j3lev commented Sep 20, 2019

I tried reproducing the issue on 2 other django projects and could not. The only main difference is that this project uses a DNS localtest.me so we can have subdomains easily without hardcoding them all in the hostfile when developing locally. So a request would go out to https://somesubdomain.localtest.me:8000 but would get resolved to 127.0.0.1:8000. Could that have anything to do with it?

@karthiknadig
Copy link
Member

That should cause an issue with connection. But since it is already connecting, i don't think that is the problem. Lets try this, put these two lines just above the line where you want the breakpoint to hit. break_into_debugger() will force a break. Then share the stack. That might reveal something.

import ptvsd
ptvsd.break_into_debugger()

@j3lev
Copy link
Author

j3lev commented Sep 20, 2019

It's not breaking at all with that. As a sanity check, I added a print statement which is executing:

import ptvsd
ptvsd.break_into_debugger()
print 'please work'

@karthiknadig
Copy link
Member

When you said httpsrunserver is it starting a separate python process?

@j3lev
Copy link
Author

j3lev commented Sep 20, 2019

This is the command source code.

class Command(BaseCommand):
    def handle(self, *args, **options):
        args = 'python manage.py runserver_plus --noreload --nothreading --cert-file cert/server.crt --key-file cert/server.key'.split()
        os.execvp('python', args=args)

@karthiknadig
Copy link
Member

This is the problem. There are two options to address this.

Option 1:

Change args in launch json to directly launch the above command line:

{
            "name": "Python: Django",
            "type": "python",
            "request": "launch",
            "program": "${workspaceFolder}/manage.py",
            "console": "integratedTerminal",
            "args": [
                "runserver_plus",
                "--noreload",
                "--nothreading",
                "--cert-file",
                "cert/server.crt",
                "--key-file",
                "cert/server.key"
            ],
            "django": true,
            "pythonPath": "${workspaceFolder}/.venv/bin/python",
            "justMyCode": false
}

Option 2

If Option 1 is not possible, then see if you can replace os.execvp with os.spawn*. The debugger currently only supports os.spawn* (, this is a limitation we are working to fix see #943). This however, should work for spawn. After switching to spawn, you will need this debug config (notice the "subProcess": true:

{
            "name": "Python: Django",
            "type": "python",
            "request": "launch",
            "program": "${workspaceFolder}/manage.py",
            "console": "integratedTerminal",
            "args": [
                "httpsrunserver"
            ],
            "django": true,
            "pythonPath": "${workspaceFolder}/.venv/bin/python",
            "justMyCode": false,
            "subProcess", true,
}

I removed the "port": 8001 since we don't really use the port in the launch scenarios.

@j3lev
Copy link
Author

j3lev commented Sep 23, 2019

That did the trick! I didn't think execvp could be the culprit. Thanks for your help

@j3lev j3lev closed this as completed Sep 23, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants