Opened 22 months ago

Closed 22 months ago

Last modified 19 months ago

#34350 closed Bug (invalid)

WSGIRequest crashes when "wsgi.input" is None.

Reported by: advl Owned by: nobody
Component: Core (Other) Version: 4.2
Severity: Normal Keywords:
Cc: Nick Pope Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description (last modified by advl)

Hello !

I have a minimal Django application deployed on Lambda using Zappa. I have managed to get a working setup using the Django and Zappa defaults for version 3.2, and 4.1.7. All requests loads as expected.

However, on upgrade to 4.2a1, the lambda endpoint returns a 500 error :

When accessing directly the endpoint, the stack trace displays the following :

"{'message': 'An uncaught exception happened while servicing this request. You can investigate this with the `zappa tail` command.', 'traceback': ['Traceback (most recent call last):\\n', '  File \"/var/task/handler.py\", line 591, in handler\\n    with Response.from_app(self.wsgi_app, environ) as response:\\n', '  File \"/var/task/werkzeug/wrappers/response.py\", line 291, in from_app\\n    return cls(*run_wsgi_app(app, environ, buffered))\\n', '  File \"/var/task/werkzeug/test.py\", line 1243, in run_wsgi_app\\n    app_rv = app(environ, start_response)\\n', '  File \"/var/task/zappa/middleware.py\", line 58, in __call__\\n    response = self.application(environ, encode_response)\\n', '  File \"/var/task/django/core/handlers/wsgi.py\", line 133, in __call__\\n    request = self.request_class(environ)\\n', '  File \"/var/task/django/core/handlers/wsgi.py\", line 81, in __init__\\n    self._stream = LimitedStream(self.environ[\"wsgi.input\"], content_length)\\n', '  File \"/var/task/django/core/handlers/wsgi.py\", line 24, in __init__\\n    self._read = stream.read\\n', \"AttributeError: 'NoneType' object has no attribute 'read'\\n\"]}"

And from the lambda logs on CloudWatch (equivalent to zappa tail)

`2023-02-17T22:25:42.303+01:00 : 'NoneType' object has no attribute 'read'`

As zappa seems to be a bit stale, I am wondering whether it would be preferable to keep the interface working on django's side longer ? Or is the more compliant and strict wsgi the way to go for django, even if this might introduce breaking changes for people using this setup ?

For reference, this is how I believe Django's wsgi is called https://github.com/zappa/Zappa/blob/master/zappa/middleware.py

(I categorized this bug as "Core (Other)" after hesitating to put it in the category HTTP handling.)

Change History (3)

comment:1 by advl, 22 months ago

Description: modified (diff)

comment:2 by Mariusz Felisiak, 22 months ago

Cc: Nick Pope added
Resolution: invalid
Status: newclosed
Summary: Django 4.2a1 Breaks serverless WSGI lambda build : 'NoneType' object has no attribute 'read'WSGIRequest crashes when "wsgi.input" is None.

This is a documented breaking change:

"Manually instantiated WSGIRequest objects must be provided a file-like object for wsgi.input. Previously, Django was more lax than the expected behavior as specified by the WSGI specification."

comment:3 by philclaridge, 19 months ago

See https://github.com/zappa/Zappa/issues/1230 for Zappa workaround and details.

Note: See TracTickets for help on using tickets.
Back to Top