Skip to content

Channels + rest framework: exception after file upload causes endless exception loop #753

Closed
@alexmnazarenko

Description

@alexmnazarenko

I've encountered a very annoying bug that seems directly related to channels.AsgiRequest.

  • Channels + asgi_redis
  • Django debug turned on
  • Have a django/rest_framework handler accepting a file upload
  • raise from this handler
  • While attempting to return 500 response page, Django will raise exception again
  • Catches exception, and tries to return 500 again...

  • OS, runtime environment,browser: Ubuntu 16.04, Python 3.6, curl )
  • Library versions: channels-1.1.8, daphne-1.3.0, django-1.11.5, twisted-17.9.0, asgi_redis-1.4.3, rest_framework-3.6.4
  • Django debug turned on (important)
  • Expected behavior: show an exception message in log, return 500 to the client
  • Actual behavior: exception loops in the server, client hangs
  • How you're running Channels: runserver + redis. Same situation with daphne.
  • Console logs and full tracebacks of any errors:
    This exception repeats in the 'loop':
Traceback (most recent call last):
  File "/home/alexey.nazarenko/.pyenv/versions/p7reloaded_py/lib/python3.6/site-packages/django/core/handlers/exception.py", line 41, in inner
    response = get_response(request)
  File "/home/alexey.nazarenko/.pyenv/versions/p7reloaded_py/lib/python3.6/site-packages/django/utils/deprecation.py", line 140, in __call__
    response = self.get_response(request)
  File "/home/alexey.nazarenko/.pyenv/versions/p7reloaded_py/lib/python3.6/site-packages/django/core/handlers/exception.py", line 43, in inner
    response = response_for_exception(request, exc)
  File "/home/alexey.nazarenko/.pyenv/versions/p7reloaded_py/lib/python3.6/site-packages/django/core/handlers/exception.py", line 93, in response_for_exception
    response = handle_uncaught_exception(request, get_resolver(get_urlconf()), sys.exc_info())
  File "/home/alexey.nazarenko/.pyenv/versions/p7reloaded_py/lib/python3.6/site-packages/django/core/handlers/exception.py", line 139, in handle_uncaught_exception
    return debug.technical_500_response(request, *exc_info)
  File "/home/alexey.nazarenko/.pyenv/versions/p7reloaded_py/lib/python3.6/site-packages/django/views/debug.py", line 81, in technical_500_response
    text = reporter.get_traceback_text()
  File "/home/alexey.nazarenko/.pyenv/versions/p7reloaded_py/lib/python3.6/site-packages/django/views/debug.py", line 333, in get_traceback_text
    c = Context(self.get_traceback_data(), autoescape=False, use_l10n=False)
  File "/home/alexey.nazarenko/.pyenv/versions/p7reloaded_py/lib/python3.6/site-packages/django/views/debug.py", line 300, in get_traceback_data
    'filtered_POST_items': list(self.filter.get_post_parameters(self.request).items()),
  File "/home/alexey.nazarenko/.pyenv/versions/p7reloaded_py/lib/python3.6/site-packages/django/views/debug.py", line 167, in get_post_parameters
    return request.POST
  File "/home/alexey.nazarenko/.pyenv/versions/p7reloaded_py/lib/python3.6/site-packages/channels/handler.py", line 160, in _get_post
    self._load_post_and_files()
  File "/home/alexey.nazarenko/.pyenv/versions/p7reloaded_py/lib/python3.6/site-packages/django/http/request.py", line 299, in _load_post_and_files
    self._post, self._files = self.parse_file_upload(self.META, data)
  File "/home/alexey.nazarenko/.pyenv/versions/p7reloaded_py/lib/python3.6/site-packages/django/http/request.py", line 255, in parse_file_upload
    warning="You cannot alter upload handlers after the upload has been processed."
  File "/home/alexey.nazarenko/.pyenv/versions/p7reloaded_py/lib/python3.6/site-packages/django/http/request.py", line 248, in upload_handlers
    raise AttributeError("You cannot set the upload handlers after the upload has been processed.")
AttributeError: You cannot set the upload handlers after the upload has been processed.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions