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

Stack overflow when using Django Debug Toolbar 1.8 (works fine in 1.7) #950

Closed
FlipperPA opened this issue Jun 1, 2017 · 11 comments
Closed

Comments

@FlipperPA
Copy link
Member

FlipperPA commented Jun 1, 2017

Good afternoon, I'm getting a stack overflow error when I try to use DJDT 1.8 on routes served by the Wagtail CMS. The same routes / pages work with DJDT 1.7. I'm running Django 1.11.2 and Wagtail 1.10.1. Here's the trace:

Fatal Python error: Cannot recover from stack overflow.

Current thread 0x00007f5d3f7f8700 (most recent call first):
  File "/venv-path/django/utils/functional.py", line 215 in wrapper
  File "/venv-path/django/template/base.py", line 835 in __init__
  File "/venv-path/django/template/base.py", line 685 in __init__
  File "/venv-path/django/template/base.py", line 600 in compile_filter
  File "/venv-path/django/template/defaulttags.py", line 826 in do_for
  File "/venv-path/django/template/base.py", line 513 in parse
  File "/venv-path/django/template/base.py", line 230 in compile_nodelist
  File "/venv-path/django/template/base.py", line 191 in __init__
  File "/venv-path/django/template/loaders/base.py", line 44 in get_template
  File "/venv-path/django/template/engine.py", line 136 in find_template
  File "/venv-path/django/template/engine.py", line 162 in get_template
  File "/venv-path/django/template/backends/django.py", line 39 in get_template
  File "/venv-path/django/template/loader.py", line 21 in get_template
  File "/venv-path/django/template/loader.py", line 67 in render_to_string
  File "/venv-path/wagtail/wagtailcore/blocks/base.py", line 259 in render
  File "/venv-path/wagtail/wagtailcore/blocks/stream_block.py", line 377 in __html__
  File "/venv-path/wagtail/wagtailcore/blocks/stream_block.py", line 380 in __str__
  File "/venv-path/django/utils/encoding.py", line 76 in force_text
  File "/venv-path/debug_toolbar/panels/templates/panel.py", line 128 in _store_template_info
  File "/venv-path/django/dispatch/dispatcher.py", line 193 in <listcomp>
  File "/venv-path/django/dispatch/dispatcher.py", line 193 in send
  File "/venv-path/django/test/utils.py", line 106 in instrumented_test_render
  File "/venv-path/django/template/base.py", line 207 in render
  File "/venv-path/django/template/backends/django.py", line 66 in render
  File "/venv-path/django/template/loader.py", line 68 in render_to_string
  File "/venv-path/wagtail/wagtailcore/blocks/base.py", line 259 in render
  File "/venv-path/wagtail/wagtailcore/blocks/stream_block.py", line 377 in __html__
  File "/venv-path/wagtail/wagtailcore/blocks/stream_block.py", line 380 in __str__
  File "/venv-path/django/utils/encoding.py", line 76 in force_text
  File "/venv-path/debug_toolbar/panels/templates/panel.py", line 128 in _store_template_info
  File "/venv-path/django/dispatch/dispatcher.py", line 193 in <listcomp>
  File "/venv-path/django/dispatch/dispatcher.py", line 193 in send
  File "/venv-path/django/test/utils.py", line 106 in instrumented_test_render
  File "/venv-path/django/template/base.py", line 207 in render
  File "/venv-path/django/template/backends/django.py", line 66 in render
  File "/venv-path/django/template/loader.py", line 68 in render_to_string
  File "/venv-path/wagtail/wagtailcore/blocks/base.py", line 259 in render
  File "/venv-path/wagtail/wagtailcore/blocks/stream_block.py", line 377 in __html__
  File "/venv-path/wagtail/wagtailcore/blocks/stream_block.py", line 380 in __str__
  File "/venv-path/django/utils/encoding.py", line 76 in force_text
  File "/venv-path/debug_toolbar/panels/templates/panel.py", line 128 in _store_template_info
  File "/venv-path/django/dispatch/dispatcher.py", line 193 in <listcomp>
  File "/venv-path/django/dispatch/dispatcher.py", line 193 in send
  File "/venv-path/django/test/utils.py", line 106 in instrumented_test_render
  File "/venv-path/django/template/base.py", line 207 in render
  File "/venv-path/django/template/backends/django.py", line 66 in render
  File "/venv-path/django/template/loader.py", line 68 in render_to_string
  File "/venv-path/wagtail/wagtailcore/blocks/base.py", line 259 in render
  File "/venv-path/wagtail/wagtailcore/blocks/stream_block.py", line 377 in __html__
  File "/venv-path/wagtail/wagtailcore/blocks/stream_block.py", line 380 in __str__
  File "/venv-path/django/utils/encoding.py", line 76 in force_text
  File "/venv-path/debug_toolbar/panels/templates/panel.py", line 128 in _store_template_info
  File "/venv-path/django/dispatch/dispatcher.py", line 193 in <listcomp>
  File "/venv-path/django/dispatch/dispatcher.py", line 193 in send
  File "/venv-path/django/test/utils.py", line 106 in instrumented_test_render
  File "/venv-path/django/template/base.py", line 207 in render
  File "/venv-path/django/template/backends/django.py", line 66 in render
  File "/venv-path/django/template/loader.py", line 68 in render_to_string
  File "/venv-path/wagtail/wagtailcore/blocks/base.py", line 259 in render
  File "/venv-path/wagtail/wagtailcore/blocks/stream_block.py", line 377 in __html__
  File "/venv-path/wagtail/wagtailcore/blocks/stream_block.py", line 380 in __str__
  File "/venv-path/django/utils/encoding.py", line 76 in force_text
  File "/venv-path/debug_toolbar/panels/templates/panel.py", line 128 in _store_template_info
  File "/venv-path/django/dispatch/dispatcher.py", line 193 in <listcomp>
  File "/venv-path/django/dispatch/dispatcher.py", line 193 in send
  File "/venv-path/django/test/utils.py", line 106 in instrumented_test_render
  File "/venv-path/django/template/base.py", line 207 in render
  File "/venv-path/django/template/backends/django.py", line 66 in render
  File "/venv-path/django/template/loader.py", line 68 in render_to_string
  File "/venv-path/wagtail/wagtailcore/blocks/base.py", line 259 in render
  File "/venv-path/wagtail/wagtailcore/blocks/stream_block.py", line 377 in __html__
  File "/venv-path/wagtail/wagtailcore/blocks/stream_block.py", line 380 in __str__
  File "/venv-path/django/utils/encoding.py", line 76 in force_text
  File "/venv-path/debug_toolbar/panels/templates/panel.py", line 128 in _store_template_info
  File "/venv-path/django/dispatch/dispatcher.py", line 193 in <listcomp>
  File "/venv-path/django/dispatch/dispatcher.py", line 193 in send
  File "/venv-path/django/test/utils.py", line 106 in instrumented_test_render
  File "/venv-path/django/template/base.py", line 207 in render
  File "/venv-path/django/template/backends/django.py", line 66 in render
  File "/venv-path/django/template/loader.py", line 68 in render_to_string
  File "/venv-path/wagtail/wagtailcore/blocks/base.py", line 259 in render
  File "/venv-path/wagtail/wagtailcore/blocks/stream_block.py", line 377 in __html__
  File "/venv-path/wagtail/wagtailcore/blocks/stream_block.py", line 380 in __str__
  File "/venv-path/django/utils/encoding.py", line 76 in force_text
  File "/venv-path/debug_toolbar/panels/templates/panel.py", line 128 in _store_template_info
  File "/venv-path/django/dispatch/dispatcher.py", line 193 in <listcomp>
  File "/venv-path/django/dispatch/dispatcher.py", line 193 in send
  File "/venv-path/django/test/utils.py", line 106 in instrumented_test_render
  File "/venv-path/django/template/base.py", line 207 in render
  File "/venv-path/django/template/backends/django.py", line 66 in render
  File "/venv-path/django/template/loader.py", line 68 in render_to_string
  File "/venv-path/wagtail/wagtailcore/blocks/base.py", line 259 in render
  File "/venv-path/wagtail/wagtailcore/blocks/stream_block.py", line 377 in __html__
  File "/venv-path/wagtail/wagtailcore/blocks/stream_block.py", line 380 in __str__
  File "/venv-path/django/utils/encoding.py", line 76 in force_text
  File "/venv-path/debug_toolbar/panels/templates/panel.py", line 128 in _store_template_info
  File "/venv-path/django/dispatch/dispatcher.py", line 193 in <listcomp>
  File "/venv-path/django/dispatch/dispatcher.py", line 193 in send
  File "/venv-path/django/test/utils.py", line 106 in instrumented_test_render
  File "/venv-path/django/template/base.py", line 207 in render
  ...

Thread 0x00007f5d4bcb3700 (most recent call first):
  File "/usr/lib64/python3.5/selectors.py", line 376 in select
  File "/usr/lib64/python3.5/socketserver.py", line 232 in serve_forever
  File "/venv-path/django/core/servers/basehttp.py", line 174 in run
  File "/venv-path/django/core/management/commands/runserver.py", line 149 in inner_run
  File "/venv-path/django/utils/autoreload.py", line 227 in wrapper

Thread 0x00007f5d61887740 (most recent call first):
  File "/venv-path/django/utils/autoreload.py", line 281 in reloader_thread
  File "/venv-path/django/utils/autoreload.py", line 298 in python_reloader
  File "/venv-path/django/utils/autoreload.py", line 332 in main
  File "/venv-path/django/core/management/commands/runserver.py", line 110 in run
  File "/venv-path/django/core/management/commands/runserver.py", line 101 in handle
  File "/venv-path/django/core/management/base.py", line 330 in execute
  File "/venv-path/django/core/management/commands/runserver.py", line 62 in execute
  File "/venv-path/django/core/management/base.py", line 283 in run_from_argv
  File "/venv-path/django/core/management/__init__.py", line 355 in execute
  File "/venv-path/django/core/management/__init__.py", line 363 in execute_from_command_line
  File "manage.py", line 15 in <module>
Aborted

I'm fine with running 1.7 for now, but am at a loss with where to start digging into this issue. Any ideas, advice, or hopefully solutions? Thanks in advance.

@patchman-daniel
Copy link

I can confirm the same problem when using DDT 1.8 with Django 1.8.

@mcoconnor
Copy link

I've seen the same issue--it was triggered for me when using a StreamField block that specified a template. Adding that template to the SKIP_TEMPLATE_PREFIXES debug toolbar config was a workaround. As I recall (though it was some time ago), the root issue was that the block object renders a template in its __str__ method, which led to infinite recursion in the TEMPLATES panel of the debug toolbar.

@FlipperPA
Copy link
Member Author

@gasman I thought you might want to have a look at this issue.

@gasman
Copy link

gasman commented Jun 6, 2017

Possibly related to wagtail/wagtail#2874...?

@smendes
Copy link

smendes commented Jun 7, 2017

I've experienced the same thing with DDT 1.8, Django 1.11.2 and Wagtail 1.10.1.
Reproduced it with Python 3.6, 3.6.1 and 3.7a

After some investigation, there is an infinite loop created in panels.py:128, in Wagtail's case the value here can be a StructValue which string representation is actually a template rendering which triggers a signal template_rendered.

@FlipperPA
Copy link
Member Author

I've monkey-patched it to get it working for those using Wagtail. The patch is here:

FlipperPA@e68cfa5

I don't expect this should be a P.R., since it is Wagtail specific.

@milkaknap
Copy link

Another hotfix for this is to exclude templates used by StructBlock from debug toolbar. E.g.

class MyStructBlock(StructBlock):
    ...
    class Meta:
        ...
        template = 'myblocks/structblock.html'

And add to settings.py file:

DEBUG_TOOLBAR_CONFIG = {
    'SKIP_TEMPLATE_PREFIXES': ('django/forms/widgets/', 'admin/widgets/', 'myblocks/structblock.html'),
}

From DDT doc for SKIP_TEMPLATE_PREFIXES:

Templates starting with those strings are skipped when collecting rendered templates and contexts. Template-based form widgets are skipped by default because the panel HTML can easily grow to hundreds of megabytes with many form fields and many options.

Works for me.

@patchman-sebastiaan
Copy link

We had this issue with Django Debug Toolbar 1.8 and django-floppyforms and fixed this problem in a similar way:

DEBUG_TOOLBAR_CONFIG = {
    'SKIP_TEMPLATE_PREFIXES': (
        'django/forms/widgets/',
        'admin/widgets/',
        'floppyforms/'
    ),
    'DISABLE_PANELS': {
        'debug_toolbar.panels.redirects.RedirectsPanel',
        'debug_toolbar.panels.redirects.TemplatesPanel'
    },
}

We also decided to disable the TemplatesPanel by default because it was slowing the page heavily. Page loads were three times as slow in comparison with Django Debug Toolbar 1.7.

msheiny added a commit to freedomofpress/pressfreedomtracker.us that referenced this issue Jul 26, 2017
This issue is outlined in
django-commons/django-debug-toolbar#950 and seems to crop up
when one has debug toolbar enabled and attempts to add an incident.
msheiny added a commit to freedomofpress/pressfreedomtracker.us that referenced this issue Jul 26, 2017
This issue is outlined in
django-commons/django-debug-toolbar#950 and seems to crop up
when one has debug toolbar enabled and attempts to add an incident.
harrislapiroff added a commit to freedomofpress/pressfreedomtracker.us that referenced this issue Jul 26, 2017
gasman added a commit to gasman/wagtail that referenced this issue Jul 27, 2017
This is liable to cause infinite loops on debug / logging code that attempts to log the fact that it's rendered a template with this value in the context.

Fixes wagtail#2874, django-commons/django-debug-toolbar#950
@gasman
Copy link

gasman commented Jul 27, 2017

Fixed in wagtail/wagtail#3738 - I think this can be closed, as it's a Wagtail issue.

@aaugustin
Copy link
Contributor

Thanks @gasman!

gasman added a commit to wagtail/wagtail that referenced this issue Aug 2, 2017
This is liable to cause infinite loops on debug / logging code that attempts to log the fact that it's rendered a template with this value in the context.

Fixes #2874, django-commons/django-debug-toolbar#950
kleingeist pushed a commit to liqd/a4-meinberlin that referenced this issue Aug 15, 2017
@int-ua
Copy link

int-ua commented Oct 3, 2017

Also affects django-el-pagination==3.1.0, adding 'el_pagination/', to SKIP_TEMPLATE_PREFIXES helps.

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

No branches or pull requests

9 participants