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

Commit

Permalink
Don't report variable errors silenced by django. Fixes #1276
Browse files Browse the repository at this point in the history
  • Loading branch information
fabioz committed Apr 4, 2019
1 parent fe974cf commit 19317ce
Show file tree
Hide file tree
Showing 8 changed files with 66 additions and 10 deletions.
32 changes: 22 additions & 10 deletions src/ptvsd/_vendored/pydevd/pydevd_plugins/django_debug.py
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,17 @@ def _is_django_variable_does_not_exist_exception_break_context(frame):
name = None
return name in ('_resolve_lookup', 'find_template')


def _is_ignoring_failures(frame):
while frame is not None:
if frame.f_code.co_name == 'resolve':
ignore_failures = frame.f_locals.get('ignore_failures')
if ignore_failures:
return True
frame = frame.f_back

return False

#=======================================================================================================================
# Django Step Commands
#=======================================================================================================================
Expand Down Expand Up @@ -520,15 +531,16 @@ def exception_break(plugin, main_debugger, pydb_frame, frame, args, arg):

elif exception.__name__ == 'VariableDoesNotExist':
if _is_django_variable_does_not_exist_exception_break_context(frame):
render_frame = _find_django_render_frame(frame)
if render_frame:
suspend_frame = suspend_django(
main_debugger, thread, DjangoTemplateFrame(render_frame), CMD_ADD_EXCEPTION_BREAK)
if suspend_frame:
add_exception_to_frame(suspend_frame, (exception, value, trace))
thread.additional_info.pydev_message = 'VariableDoesNotExist'
suspend_frame.f_back = frame
frame = suspend_frame
return True, frame
if not getattr(exception, 'silent_variable_failure', False) and not _is_ignoring_failures(frame):
render_frame = _find_django_render_frame(frame)
if render_frame:
suspend_frame = suspend_django(
main_debugger, thread, DjangoTemplateFrame(render_frame), CMD_ADD_EXCEPTION_BREAK)
if suspend_frame:
add_exception_to_frame(suspend_frame, (exception, value, trace))
thread.additional_info.pydev_message = 'VariableDoesNotExist'
suspend_frame.f_back = frame
frame = suspend_frame
return True, frame

return None
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{% if pat.name %}
pat.name={{ pat.name }}
{% else %}
no_pat_name
{% endif %}
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@
url(r'^template_error$', views.template_error, name='template_error'),
url(r'^template_error2$', views.template_error2, name='template_error2'),
url(r'^inherits$', views.inherits, name='inherits'),
url(r'^no_var_error$', views.no_var_error, name='no_var_error'),
]
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,9 @@ def template_error2(request):
context = {}
ret = render(request, 'my_app/template_error2.html', context)
return ret


def no_var_error(request):
context = {}
ret = render(request, 'my_app/no_var_error.html', context)
return ret
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{% if pat.name %}
pat.name={{ pat.name }}
{% else %}
no_pat_name
{% endif %}
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@
url(r'^template_error2$', views.template_error2, name='template_error2'),
url(r'^template_error$', views.template_error, name='template_error'),
url(r'^inherits$', views.inherits, name='inherits'),
url(r'^no_var_error$', views.no_var_error, name='no_var_error'),
]
Original file line number Diff line number Diff line change
Expand Up @@ -72,3 +72,9 @@ def inherits(request):
context = {}
ret = render(request, 'my_app/inherits.html', context)
return ret


def no_var_error(request):
context = {}
ret = render(request, 'my_app/no_var_error.html', context)
return ret
20 changes: 20 additions & 0 deletions src/ptvsd/_vendored/pydevd/tests_python/test_debugger.py
Original file line number Diff line number Diff line change
Expand Up @@ -963,6 +963,26 @@ def test_case_django_template_inherits_no_exception(case_setup_django):
writer.finished_ok = True


@pytest.mark.skipif(not TEST_DJANGO, reason='No django available')
def test_case_django_no_var_error(case_setup_django):
with case_setup_django.test_file(EXPECTED_RETURNCODE='any') as writer:

# Check that it doesn't have issues with inherits + django exception breakpoints.
writer.write_add_exception_breakpoint_django()

writer.write_make_initial_run()

t = writer.create_request_thread('my_app/no_var_error')
time.sleep(5) # Give django some time to get to startup before requesting the page
t.start()
contents = t.wait_for_contents()

contents = contents.replace(' ', '').replace('\r', '').replace('\n', '')
assert contents == '''no_pat_name'''

writer.finished_ok = True


@pytest.mark.skipif(not TEST_DJANGO, reason='No django available')
@pytest.mark.parametrize("jmc", [False, True])
def test_case_django_no_attribute_exception_breakpoint(case_setup_django, jmc):
Expand Down

0 comments on commit 19317ce

Please sign in to comment.