Skip to content
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

Debugger crashes when using Django's Development Server with a Proper Launch Profile #4988

Closed
pymike00 opened this issue Mar 28, 2019 · 4 comments
Labels
area-debugging bug Issue identified by VS Code Team member as probable bug regression Bug didn't exist in a previous release

Comments

@pymike00
Copy link

pymike00 commented Mar 28, 2019

Environment data

  • VS Code version: 1.32.2-1
  • Extension version: 2019.3.6139
  • OS and version: Linux Manjaro XFCE x86_64 18.0.4
  • Python version: 3.7.2
  • Type of virtual environment used: venv
  • Relevant/affected Python packages and their versions: Django 2.1.7

Expected behaviour

Using the Python Extension on Visual Studio Code to run Django's development server as explained in the docs, https://code.visualstudio.com/docs/python/tutorial-django#_create-a-debugger-launch-profile, without any problems.

Actual behaviour

Can't use the debugger to launch Django's development server; As soon as you try to use the site, the debugger pauses on the exception VariableDoesNotExist, even on a fresh Django Project.

The problem does not manifest itself when using a previous version of the Python Extension (such as 2019.2.5558), nor it manifests itself when running Django's development server from a shell, or even from VS Code's Terminal.

Steps to reproduce:

  1. Create a Virtual Environment with VENV and install Django.
  2. Create New Project: django-admin startproject NewProject
  3. Enter Folder: cd NewProject
  4. Open The Editor: code .
  5. Select Python Interpreter to be the one of the previously created VENV
  6. Create debugger Launch profile as explained in the docs. Comment out "no threading"
  7. Launch dev Server with the newly created Launch profile (terminal will show no problems)
  8. Open Chrome, go to localhost:8000. Hello World Page will load, but VS Code will show "Could not load source '': Source unavailable.". Debugger paused on exception
  9. Go to localhost:8000/admin/. Debugger will pause on exception VariableDoesNotExist as shown below.

Logs

Impossible to get the output as explained from the Output panel in Python: it is empty and the development server doesn't show any problem. Everything works fine if running Django's development server from a shell or from the terminal. The log below is the message shown in red (as shown in the screenshot) with the VariableDoesNotExist exception.

Exception has occurred: VariableDoesNotExist
Failed lookup for key [is_popup] in [{'True': True, 'False': False, 'None': None}, {'csrf_token': <SimpleLazyObject: <function csrf.<locals>._get_val at 0x7fe8884261e0>>, 'request': <WSGIRequest: GET '/admin/login/?next=/admin/'>, 'user': <SimpleLazyObject: <django.contrib.auth.models.AnonymousUser object at 0x7fe8884740b8>>, 'perms': <django.contrib.auth.context_processors.PermWrapper object at 0x7fe88839c7b8>, 'messages': <django.contrib.messages.storage.fallback.FallbackStorage object at 0x7fe8884747f0>, 'DEFAULT_MESSAGE_LEVELS': {'DEBUG': 10, 'INFO': 20, 'SUCCESS': 25, 'WARNING': 30, 'ERROR': 40}}, {}, {'form': <AdminAuthenticationForm bound=False, valid=Unknown, fields=(username;password)>, 'view': <django.contrib.auth.views.LoginView object at 0x7fe8883da9b0>, 'site_title': 'Django site admin', 'site_header': 'Django administration', 'site_url': '/', 'has_permission': False, 'available_apps': [], 'title': 'Log in', 'app_path': '/admin/login/?next=/admin/', 'username': '', 'next': '/admin/', 'site': <django.contrib.sites.requests.RequestSite object at 0x7fe888474668>, 'site_name': '127.0.0.1:8000', 'LANGUAGE_CODE': 'en-us', 'LANGUAGE_BIDI': False}]
  File "/home/pymike00/Desktop/TestWithFreshProject/venv/lib/python3.7/site-packages/django/template/base.py", line 850, in _resolve_lookup
    (bit, current))  # missing attribute
  File "/home/pymike00/Desktop/TestWithFreshProject/venv/lib/python3.7/site-packages/django/template/base.py", line 796, in resolve
    value = self._resolve_lookup(context)
  File "/home/pymike00/Desktop/TestWithFreshProject/venv/lib/python3.7/site-packages/django/template/base.py", line 671, in resolve
    obj = self.var.resolve(context)
  File "/home/pymike00/Desktop/TestWithFreshProject/venv/lib/python3.7/site-packages/django/template/defaulttags.py", line 875, in eval
    return self.value.resolve(context, ignore_failures=True)
  File "/home/pymike00/Desktop/TestWithFreshProject/venv/lib/python3.7/site-packages/django/template/defaulttags.py", line 302, in render
    match = condition.eval(context)
  File "/home/pymike00/Desktop/TestWithFreshProject/venv/lib/python3.7/site-packages/django/template/base.py", line 904, in render_annotated
    return self.render(context)
  File "/home/pymike00/Desktop/TestWithFreshProject/venv/lib/python3.7/site-packages/django/template/base.py", line 937, in render
    bit = node.render_annotated(context)
  File "/home/pymike00/Desktop/TestWithFreshProject/venv/lib/python3.7/site

Output from Console under the Developer Tools panel (toggle Developer Tools on under Help; turn on source maps to make any tracebacks be useful by running Enable source map support for extension debugging)

[Extension Host] Python Extension: Cached data exists getEnvironmentVariables, <unknown source>
console.ts:134 [Extension Host] Python Extension: Cached data exists getEnvironmentVariables, /home/pymike00/Desktop/TestWithFreshProject/venv/lib/python3.7/site-packages/django/contrib/admin/templates/admin/base.html

The following is a screenshot of everything explained above. Chrome just hangs. No page or error is shown. Thanks for your precious work.

screen

@ghost ghost added the triage-needed Needs assignment to the proper sub-team label Mar 28, 2019
@ohlr
Copy link

ohlr commented Mar 28, 2019

I can confirm this bug:

Version: 1.32.3
Commit: a3db5be9b5c6ba46bb7555ec5d60178ecc2eaae4
Date: 2019-03-14T23:38:49.842Z
Electron: 3.1.6
Chrome: 66.0.3359.181
Node.js: 10.2.0
V8: 6.6.346.32
OS: Linux x64 4.15.0-46-generic

As quick fix use the following launch.json

        {
            "name": "Python: Django",
            "type": "python",
            "request": "launch",
            "program": "${workspaceFolder}/my_project/manage.py",
            "console": "integratedTerminal",
            "args": [
                "runserver",
                "--noreload",
                "--nothreading",
            ],
            "django": false <- **if true template rendering does not work correctly**
        },

@pymike00
Copy link
Author

pymike00 commented Mar 28, 2019

This works on my setup as well, with "--nothreading" commented out (I have always been commenting out "--nothreading" as suggested by VSCode docs, considering that I normally develop on Chromium).
Thanks for sharing!

As quick fix use the following launch.json

    {
        "name": "Python: Django",
        "type": "python",
        "request": "launch",
        "program": "${workspaceFolder}/my_project/manage.py",
        "console": "integratedTerminal",
        "args": [
            "runserver",
            "--noreload",
            "--nothreading",
        ],
        "django": false <- **if true template rendering does not work correctly**
    },

@DonJayamanne DonJayamanne added bug Issue identified by VS Code Team member as probable bug area-debugging upstream-ptvsd regression Bug didn't exist in a previous release labels Mar 28, 2019
@ghost ghost removed the triage-needed Needs assignment to the proper sub-team label Mar 28, 2019
@subodhjena
Copy link

Yup, Confirmed. It happens with the new update.
@ohlr answer fixes it temporarily. Thanks.

@DonJayamanne
Copy link

This has been resolved upstream and we'll be shipping a fix for this.

@gramster gramster closed this as completed Sep 3, 2019
@ghost ghost removed the needs upstream fix label Sep 3, 2019
@lock lock bot locked as resolved and limited conversation to collaborators Sep 10, 2019
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 regression Bug didn't exist in a previous release
Projects
None yet
Development

No branches or pull requests

5 participants