Skip to content

Django app behaves differently when debugging #204

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
DonJayamanne opened this issue Nov 14, 2017 · 10 comments
Closed

Django app behaves differently when debugging #204

DonJayamanne opened this issue Nov 14, 2017 · 10 comments
Assignees
Labels
area-debugging bug Issue identified by VS Code Team member as probable bug
Milestone

Comments

@DonJayamanne
Copy link

From @albertinix on October 19, 2017 8:1

Environment data

VS Code version: 1.17.2
Python Extension version: 0.7.0
Python Version: 3.6.0
OS and version: Windows 7 64-bit

Actual behavior

I have a Django app, with a view and a form.
The interesting part is here:

loginForm = LoginForm(request.POST or None)

If I set a breakpoint at that line and then skip over it (with F10), then the loginForm object will not be bound (the is_bound property of the form is false).
If however I set the breakpoint one line after that, the loginForm object will be bound.

This is just one example. It happens multiple times over various objects and functions: if I set the breakpoint at one line when calling a function, the result will be "a" (not expected), while if I set the breakpoint after that line, the result is the expected "b".

The debugger seems, in some cases, to introduce some kind of mistakes in code execution.

P.S.: I checked the same app in PyCharm Community and it behaves as it should, debugger or no debugger.

Copied from original issue: DonJayamanne/pythonVSCode#1327

@DonJayamanne
Copy link
Author

From @albertinix on October 19, 2017 8:2

At a glance, this might be also linked to https://github.com/DonJayamanne/pythonVSCode/issues/1310

@DonJayamanne
Copy link
Author

@albertinix checked #1310, I doubt that's related to this issue.
Just a heads up, the PTVS (Python for Visual Studio) team are currently in the middle of some major re-engineering to debugger (the same debugger I'm using in this extension), and I expect this issue to be resolved soon.

Will look into this and keep you posted.

@brettcannon brettcannon added awaiting 1-verification area-debugging bug Issue identified by VS Code Team member as probable bug labels Nov 14, 2017
@albertinix
Copy link

Thanks, I will investigate if the issue is still present in the newly released VSCode 1.18.

@DonJayamanne DonJayamanne added info-needed Issue requires more information from poster and removed awaiting 1-verification labels Nov 15, 2017
@brettcannon
Copy link
Member

I'm closing this as it has been over a month since we requested more info. If we do get the info at a later date we can re-open this issue.

@albertinix
Copy link

albertinix commented Jan 16, 2018

Sorry for not following up earlier. It took a while - but I have now identified the exact steps needed to reproduce the problem.

However, it is very specific. I'm not sure it belongs here or if it's related to the VSCode debugger. I will write here all the details and let's discuss afterwards.

Environment: Python 3.6, Django 1.11 (or 2.0), VSCode 1.19.1, Python extension: 0.9.1

  1. Download and unzip the attached file, containing a very small skeleton app which exhibits the behavior in question
    DjangoProject.zip
  2. Make sure you have all the requirements installed: pip install -r requirements.txt
  3. Open the folder with VSCode
  4. Start debugging using the "Python: Django" built-in profile
  5. Navigate to "http://localhost:8000"
  6. You should see a simple form, 2 input boxes and 1 submit button
  7. Enter some values in the form, press Submit and you'll get a JSON response with the 2 submitted values

If all was good so far, let's start reproducing the issue:

  1. Put a breakpoint in "views.py" on line 9 ("form = .....")
  2. Repeat steps 5 to 7. Don't do anything in VSCode except "Continue" when the breakpoint is hit.
  3. You should notice that the JSON response this time is empty. No values have been passed.
  4. Delete the breakpoint on line 9 and put another one on line 10 ("print...")
  5. Repeat steps 5 to 7. Don't do anything except "Continue"
  6. You should notice now that the values are passed from the form to the JSON response.

It seems that the breakpoint on line 9 somehow inhibits Django to do some more processing in order to populate the "request.POST" dictionary. Normally, this member variable should already be populated when the breakpoint on that first line is hit.

I'm not entirely sure this is related to the VSCode debugger. But the fact is that without debugging the code works correctly and PyCharm does not exhibit this functionality (breakpoint on first line, "request.POST" populated correctly).

Note that in order for this behaviour to be reproduced, line 7 "@csrf_exempt" must be present. If we delete this annotation (which means that Django must do some more processing for the CSRF token), then the "request.POST" dictionary is always populated, no matter where the breakpoint is set.

Please test and let me know your thoughts.

@albertinix
Copy link

I can confirm that this behavior is also present on Visual Studio 2017 with Python tools. So maybe this bug should also be put on PTVS.

Visual Studio 2017 Community Edition (version 15.4.1)
Python tools: 3.0.17262.1
Python version: 3.6

@DonJayamanne
Copy link
Author

Thanks for confirming this.

@nashmaniac
Copy link

@DonJayamanne This issue still persists.
Environments:
VSCode: 1.20.0
Magic Python: 1.0.12
Microsoft Python: 2018.1.0
Python Extension Pack: 1.0.1

@DonJayamanne
Copy link
Author

DonJayamanne commented Feb 19, 2018

@DonJayamanne This issue still persists.

@Taitalus the issue has not yet been fixed. Please monitor the status (Labels) of the issue or wait for it to be closed.

@DonJayamanne DonJayamanne added this to the May 2018 milestone May 4, 2018
@DonJayamanne DonJayamanne self-assigned this May 4, 2018
@DonJayamanne
Copy link
Author

Duplicate of #170

@DonJayamanne DonJayamanne marked this as a duplicate of #170 May 8, 2018
@lock lock bot locked as resolved and limited conversation to collaborators Jul 11, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-debugging bug Issue identified by VS Code Team member as probable bug
Projects
None yet
Development

No branches or pull requests

5 participants