Django-debug-toolbar: Lambda static storage causes crash

Created on 2 Jan 2015  路  1Comment  路  Source: jazzband/django-debug-toolbar

I have static storage defined as a lambda:

StaticStorage = lambda: S3BotoStorage(
    bucket=settings.AWS_STATIC_BUCKET_NAME,
    custom_domain=settings.AWS_STATIC_CUSTOM_DOMAIN,
)

As a result, here a lambda is passed, and since you can't inherit from a lambda, it crashes on runserver with this stack trace:

Traceback (most recent call last):
  File "/usr/local/Cellar/python3/3.4.2_1/Frameworks/Python.framework/Versions/3.4/lib/python3.4/wsgiref/handlers.py", line 137, in run
    self.result = application(self.environ, self.start_response)
  File "/Users/maryokhin/.virtualenvs/backend-drf3/lib/python3.4/site-packages/django/contrib/staticfiles/handlers.py", line 64, in __call__
    return self.application(environ, start_response)
  File "/Users/maryokhin/.virtualenvs/backend-drf3/lib/python3.4/site-packages/django/core/handlers/wsgi.py", line 187, in __call__
    response = self.get_response(request)
  File "/Users/maryokhin/.virtualenvs/backend-drf3/lib/python3.4/site-packages/django/core/handlers/base.py", line 199, in get_response
    response = self.handle_uncaught_exception(request, resolver, sys.exc_info())
  File "/Users/maryokhin/.virtualenvs/backend-drf3/lib/python3.4/site-packages/django/core/handlers/base.py", line 236, in handle_uncaught_exception
    return debug.technical_500_response(request, *exc_info)
  File "/Users/maryokhin/.virtualenvs/backend-drf3/lib/python3.4/site-packages/django/views/debug.py", line 91, in technical_500_response
    html = reporter.get_traceback_html()
  File "/Users/maryokhin/.virtualenvs/backend-drf3/lib/python3.4/site-packages/django/views/debug.py", line 349, in get_traceback_html
    c = Context(self.get_traceback_data(), use_l10n=False)
  File "/Users/maryokhin/.virtualenvs/backend-drf3/lib/python3.4/site-packages/django/views/debug.py", line 307, in get_traceback_data
    frames = self.get_traceback_frames()
  File "/Users/maryokhin/.virtualenvs/backend-drf3/lib/python3.4/site-packages/django/views/debug.py", line 465, in get_traceback_frames
    'vars': self.filter.get_traceback_frame_variables(self.request, tb.tb_frame),
  File "/Users/maryokhin/.virtualenvs/backend-drf3/lib/python3.4/site-packages/django/views/debug.py", line 232, in get_traceback_frame_variables
    cleansed[name] = self.cleanse_special_types(request, value)
  File "/Users/maryokhin/.virtualenvs/backend-drf3/lib/python3.4/site-packages/django/views/debug.py", line 187, in cleanse_special_types
    if isinstance(value, HttpRequest):
  File "/Users/maryokhin/.virtualenvs/backend-drf3/lib/python3.4/site-packages/django/utils/functional.py", line 224, in inner
    self._setup()
  File "/Users/maryokhin/.virtualenvs/backend-drf3/lib/python3.4/site-packages/debug_toolbar/panels/staticfiles.py", line 65, in _setup
    class DebugStaticFilesStorage(configured_storage_cls):
TypeError: function() argument 1 must be code, not str
[02/Jan/2015 18:11:20] "GET / HTTP/1.1" 500 59

Django 1.7.1, Python 3.4.2

Bug

Most helpful comment

For anyone looking for a workaround, just use a class instead of a lambda:

class StaticStorage(S3BotoStorage):
    def __init__(self):
        super().__init__(
            bucket=settings.AWS_STATIC_BUCKET_NAME,
            custom_domain=settings.AWS_STATIC_CUSTOM_DOMAIN,
        )

>All comments

For anyone looking for a workaround, just use a class instead of a lambda:

class StaticStorage(S3BotoStorage):
    def __init__(self):
        super().__init__(
            bucket=settings.AWS_STATIC_BUCKET_NAME,
            custom_domain=settings.AWS_STATIC_CUSTOM_DOMAIN,
        )
Was this page helpful?
0 / 5 - 0 ratings