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

Edit dictionary value hangs VS #1385

Closed
huguesv opened this issue Apr 24, 2019 · 6 comments
Closed

Edit dictionary value hangs VS #1385

huguesv opened this issue Apr 24, 2019 · 6 comments

Comments

@huguesv
Copy link
Contributor

huguesv commented Apr 24, 2019

Environment data

  • PTVSD version: 4.2.8
  • OS and version: Win10
  • Python version (& distribution if applicable, e.g. Anaconda): 3.7
  • Using VS Code or Visual Studio: VS

Actual behavior

VS hangs when editing a dict value

Expected behavior

Value in dict is changed and watch window shows the new value

Note that it works when reverting to ptvsd 4.2.0

Steps to reproduce:

  1. Enter this code
data = {
    'page': 'About',
    'description': 'About this application'
}

print(data)
  1. Add breakpoint on print
  2. Run to breakpoint
  3. In locals window, edit the value for 'page' and press enter
  4. VS puts up a waiting dialog that never ends and must be canceled
 1> [DebugAdapter] --> C (configurationDone-15): {"command":"configurationDone","arguments":{},"seq":15,"type":"request"}
 1> [DebugAdapter] <--   E (process): {"type": "event", "seq": 16, "event": "process", "body": {"name": "C:\\Users\\huvalo\\source\\repos\\editlocaltest\\editlocaltest.py", "systemProcessId": 432, "isLocalProcess": true, "startMethod": "launch"}}
 1> [DebugAdapter] <--   R (configurationDone-15) [63 ms]: {"type": "response", "seq": 17, "request_seq": 15, "success": true, "command": "configurationDone", "message": "", "body": {}}
 1> [DebugAdapter] <--   E (thread): {"type": "event", "seq": 18, "event": "thread", "body": {"reason": "started", "threadId": 1}}
 1> [DebugAdapter] <--   E (stopped): {"type": "event", "seq": 19, "event": "stopped", "body": {"reason": "breakpoint", "threadId": 1, "text": null, "description": null, "preserveFocusHint": false, "allThreadsStopped": true}}
 1> [DebugAdapter] --> C (threads-16): {"command":"threads","arguments":{},"seq":16,"type":"request"}
 1> [DebugAdapter] <--   R (threads-16) [4 ms]: {"type": "response", "seq": 20, "request_seq": 16, "success": true, "command": "threads", "message": "", "body": {"threads": [{"id": 1, "name": "MainThread"}]}}
 1> [DebugAdapter] --> C (stackTrace-17): {"command":"stackTrace","arguments":{"threadId":1,"startFrame":0,"levels":1,"format":{"includeAll":true}},"seq":17,"type":"request"}
 1> [DebugAdapter] <--   E (module): {"type": "event", "seq": 21, "event": "module", "body": {"reason": "new", "module": {"id": 0, "name": "__main__", "path": "C:\\Users\\huvalo\\source\\repos\\editlocaltest\\editlocaltest.py"}}}
 1> [DebugAdapter] <--   R (stackTrace-17) [3 ms]: {"type": "response", "seq": 22, "request_seq": 17, "success": true, "command": "stackTrace", "message": "", "body": {"stackFrames": [{"id": 1, "name": "<module>", "line": 6, "column": 1, "source": {"path": "C:\\Users\\huvalo\\source\\repos\\editlocaltest\\editlocaltest.py", "sourceReference": 0}}], "totalFrames": 1}}
 1> [DebugAdapter] --> C (stackTrace-18): {"command":"stackTrace","arguments":{"threadId":1,"startFrame":0,"levels":1000,"format":{"parameters":true,"parameterTypes":true,"parameterNames":true,"line":true,"module":true}},"seq":18,"type":"request"}
 1> [DebugAdapter] <--   R (stackTrace-18) [915 ms]: {"type": "response", "seq": 23, "request_seq": 18, "success": true, "command": "stackTrace", "message": "", "body": {"stackFrames": [{"id": 1, "name": "__main__ : 6", "line": 6, "column": 1, "source": {"path": "C:\\Users\\huvalo\\source\\repos\\editlocaltest\\editlocaltest.py", "sourceReference": 0}}], "totalFrames": 1}}
 1> [DebugAdapter] --> C (scopes-19): {"command":"scopes","arguments":{"frameId":1},"seq":19,"type":"request"}
 1> [DebugAdapter] <--   R (scopes-19) [1 ms]: {"type": "response", "seq": 24, "request_seq": 19, "success": true, "command": "scopes", "message": "", "body": {"scopes": [{"name": "Locals", "variablesReference": 1, "expensive": false, "source": {}}]}}
 1> [DebugAdapter] --> C (variables-20): {"command":"variables","arguments":{"variablesReference":1,"timeout":1000},"seq":20,"type":"request"}
 1> [DebugAdapter] <--   R (variables-20) [4 ms]: {"type": "response", "seq": 25, "request_seq": 20, "success": true, "command": "variables", "message": "", "body": {"variables": [{"name": "data", "value": "{'description': 'About this application', 'page': 'About'}", "type": "dict", "evaluateName": "data", "variablesReference": 2}, {"name": "__builtins__", "value": "{'ArithmeticError': <class 'ArithmeticError'>, 'AssertionError': <class 'AssertionError'>, 'AttributeError': <class 'AttributeError'>, 'BaseException': <class 'BaseException'>, 'BlockingIOError': <class 'BlockingIOError'>, 'BrokenPipeError': <class 'BrokenPipeError'>, 'BufferError': <class 'BufferError'>, 'BytesWarning': <class 'BytesWarning'>, 'ChildProcessError': <class 'ChildProcessError'>, 'ConnectionAbortedError': <class 'ConnectionAb...tedError'>, 'ConnectionError': <class 'ConnectionError'>, 'ConnectionRefusedError': <class 'ConnectionRe...sedError'>, 'ConnectionResetError': <class 'ConnectionResetError'>, 'DeprecationWarning': <class 'DeprecationWarning'>, ...}", "type": "dict", "evaluateName": "__builtins__", "variablesReference": 3}, {"name": "__doc__", "value": "None", "type": "NoneType", "evaluateName": "__doc__"}, {"name": "__file__", "value": "'C:\\\\Users\\\\huvalo\\\\source\\\\repos\\\\editlocaltest\\\\editlocaltest.py'", "type": "str", "evaluateName": "__file__", "presentationHint": {"attributes": ["rawString"]}}, {"name": "__loader__", "value": "<_frozen_importlib_external.SourceFileLoader object at 0x000001B54452E6A0>", "type": "SourceFileLoader", "evaluateName": "__loader__", "variablesReference": 4}, {"name": "__name__", "value": "'__main__'", "type": "str", "evaluateName": "__name__", "presentationHint": {"attributes": ["rawString"]}}, {"name": "__package__", "value": "None", "type": "NoneType", "evaluateName": "__package__"}, {"name": "__spec__", "value": "None", "type": "NoneType", "evaluateName": "__spec__"}]}}
 1> [DebugAdapter] --> C (variables-21): {"command":"variables","arguments":{"variablesReference":2,"timeout":5000},"seq":21,"type":"request"}
 1> [DebugAdapter] <--   R (variables-21) [7 ms]: {"type": "response", "seq": 26, "request_seq": 21, "success": true, "command": "variables", "message": "", "body": {"variables": [{"name": "'description'", "value": "'About this application'", "type": "str", "evaluateName": "data['description']", "presentationHint": {"attributes": ["rawString"]}}, {"name": "'page'", "value": "'About'", "type": "str", "evaluateName": "data['page']", "presentationHint": {"attributes": ["rawString"]}}, {"name": "__len__", "value": "2", "type": "int", "evaluateName": "len(data)"}]}}
 1> [DebugAdapter] --> C (evaluate-22): {"command":"evaluate","arguments":{"expression":"data['page']","frameId":1,"timeout":5000},"seq":22,"type":"request"}
 1> [DebugAdapter] <--   R (evaluate-22) [10 ms]: {"type": "response", "seq": 27, "request_seq": 22, "success": true, "command": "evaluate", "message": "", "body": {"result": "'About'", "variablesReference": 0, "type": "str", "presentationHint": {"attributes": ["rawString"]}}}
 1> [DebugAdapter] --> C (setVariable-23): {"command":"setVariable","arguments":{"variablesReference":2,"name":"'page'","value":"'Hello'","timeout":10000},"seq":23,"type":"request"}
 1> WARNING: Request 'setVariable-23' has not received a response within 1000 ms!
 1> Debug adapter process exited.
@huguesv
Copy link
Contributor Author

huguesv commented Apr 24, 2019

FYI Debug adapter process exited. is because I hit cancel which ended the Python process.

@huguesv
Copy link
Contributor Author

huguesv commented Apr 24, 2019

Arrays are also affected

@int19h
Copy link
Contributor

int19h commented Apr 24, 2019

This affects everything except for top-level variables (whether local or global) - e.g. object attributes are also affected. The underlying reason is that pydevd can't handle setVariable request for anything else:

https://github.com/Microsoft/ptvsd/blob/60da1fee417a7d37bec6e3628cd2eea4285432cf/src/ptvsd/_vendored/pydevd/_pydevd_bundle/pydevd_comm.py#L753-L758

Specifically, it only handles FrameVariable, while child variables are ObjectVariable:

https://github.com/Microsoft/ptvsd/blob/60da1fee417a7d37bec6e3628cd2eea4285432cf/src/ptvsd/_vendored/pydevd/_pydevd_bundle/pydevd_comm.py#L769-L790

It looks like this is a feature regression from pydevd JSON refactoring.

Even so it shouldn't hang the debugger, just report inability to set. The hang is a separate bug, due to this line returning the command response (whence it gets discarded), instead of sending it via py_db.writer.add_command as the code above does:

https://github.com/Microsoft/ptvsd/blob/60da1fee417a7d37bec6e3628cd2eea4285432cf/src/ptvsd/_vendored/pydevd/_pydevd_bundle/pydevd_comm.py#L790-L799

@karthiknadig
Copy link
Member

The way we had solved the list or dict edit before was by doing a evaluate/exec internally. The temporary workaround is to do that, manually.

@fabioz this should do evaluate or exec on the variable after retrieving its evaluateName. That is how we used to do this before it got moved to pydevd. this is only needed until the list/dict resolvers are updated to support setting values.

@fabioz fabioz self-assigned this Apr 25, 2019
@fabioz
Copy link
Contributor

fabioz commented Apr 25, 2019

I'll take a look at it.

@fabioz
Copy link
Contributor

fabioz commented Apr 29, 2019

As a note, my plan is to provide a pull request for this tomorrow.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants