You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Aug 2, 2023. It is now read-only.
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:
Create a Virtual Environment with VENV and install Django.
Create New Project: django-admin startproject NewProject
Enter Folder: cd NewProject
Open The Editor: code .
Select Python Interpreter to be the one of the previously created VENV
Create debugger Launch profile as explained in the docs. Comment out "no threading"
Launch dev Server with the newly created Launch profile (terminal will show no problems)
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
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.
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**
},
The text was updated successfully, but these errors were encountered:
The issue is that previously the VariableDoesNotExist wasn't always being gotten properly, which was fixed in the last release, so, when such an exception is raised now we properly report it.
The problem in this case is that there are some situations in which django raises that exception and it's expected to ignore it later on -- in which case we shouldn't report it.
Some examples on django ignoring the failures:
def resolve(self, context, ignore_failures=False): if getattr(e, 'silent_variable_failure', False):
so, I need to check a better approach to detect those exceptions (possibly checking further in the chain or reading those variables to see if it should not report that failure).
fabioz
added a commit
to fabioz/ptvsd
that referenced
this issue
Apr 4, 2019
@pymike00 commented on Thu Mar 28 2019
Environment data
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:
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.
Output from
Console
under theDeveloper Tools
panel (toggle Developer Tools on underHelp
; turn on source maps to make any tracebacks be useful by runningEnable source map support for extension debugging
)The following is a screenshot of everything explained above. Chrome just hangs. No page or error is shown. Thanks for your precious work.
@ohlr commented on Thu Mar 28 2019
I can confirm this bug:
As quick fix use the following launch.json
@pymike00 commented on Thu 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!
The text was updated successfully, but these errors were encountered: