zappa / Zappa

Serverless Python
https://zappa.ws/zappa
MIT License
3.33k stars 363 forks source link

Upgrading Django to 4.2 crashes the zappa based deployment with Error 500 #1230

Closed spirovskib closed 1 year ago

spirovskib commented 1 year ago

Context

I am running a Django web application as Lambda deployed on AWS via zappa I upgraded Django to 4.2 on my application to remedy security issues reported by Github Dependabot. Local testing didn't reveal any issues. After upgrading i ran zappa update production and the deployment failed, with zappa deployment reporting error 500 upon deployment. In the zappa log i found the following error: 'NoneType' object has no attribute 'read' I found another comment on Django forums that's closed as Django making a breaking change that requires changes in the way WSGIRequest is invoked https://code.djangoproject.com/ticket/34350 At this moment I reverted back to Django 4.1.8 for the application to run.

Is there any proper upgrade path of libraries to make Django 4.2 work?

Expected Behavior

Upgrading Django and redeployment via zappa should be trivial. Previously I have done this many times. On local testing everything is working properly.

Actual Behavior

Error 500 on redeployment through Zappa, and in the zappa log the following error: 'NoneType' object has no attribute 'read'

Possible Fix

Revert back to Django 4.1.8 for the application to run. This will make sense in the short term, but I'm looking for a long term fix.

Steps to Reproduce

  1. Have a Django 4.1.x application running on AWS Lambda, deployed via zappa.
  2. Upgrade Django to 4.2.x
  3. Try zappa update application
  4. The deployment fails, with Error 500
  5. In the zappa tail application logs one can see "NoneType' object has no attribute 'read'"

Your Environment

dennybiasiolli commented 1 year ago

The solution in my PR could be to set the value of "wsgi.input"to a file-like object, like BytesIO(body).

spirovskib commented 1 year ago

Please share if the PR is merged in a new release and whether I need to configure something in order for the process to run properly for Django 4.2+

dennybiasiolli commented 1 year ago

Yes of course, let's wait for a review from the maintainer.

The following lines are not a solution, just a temporary workaround!

If you need it ASAP, then just switch your requirements line from

zappa==0.56.1

to

zappa @ https://github.com/dennybiasiolli/Zappa/archive/refs/heads/django42.zip

So you can test it with Django 4.2 (and eventually provide another feedback other than mine)

spirovskib commented 1 year ago

Great, task for the weekend.

symbiot-india commented 1 year ago

@dennybiasiolli I'm building a new project with Django 4.2 and I'm facing the same error mentioned in the thread. I wanted to try out the updated package using zappa @ https://github.com/dennybiasiolli/Zappa/archive/refs/heads/django42.zip, but it seems like the package doesn't exist there anymore. If possible, can you please share an updated location for django42.zip, so that I can test it and provide feedback as well?

Here's the error I'm getting:

  ERROR: HTTP error 404 while getting https://github.com/dennybiasiolli/Zappa/archive/refs/heads/django42.zip
ERROR: Could not install requirement zappa@ https://github.com/dennybiasiolli/Zappa/archive/refs/heads/django42.zip from https://github.com/dennybiasiolli/Zappa/archive/refs/heads/django42.zip (from -r requirements.txt (line 33)) because of HTTP error 404 Client Error: Not Found for url: https://codeload.github.com/dennybiasiolli/Zappa/zip/refs/heads/django42 for URL https://github.com/dennybiasiolli/Zappa/archive/refs/heads/django42.zip
dennybiasiolli commented 1 year ago

@symbiot-india my pull request has been approved and merged into Zappa:master, so you can use the official zappa repo with zappa @ https://github.com/zappa/Zappa/archive/refs/heads/master.zip or other official methods like git+https or similar.

symbiot-india commented 1 year ago

Thanks! I will try this out.

symbiot-india commented 1 year ago

Great, it's working now with Django 4.2! Thanks Denny

philclaridge commented 1 year ago

Fixed for me as well. Thank you.

monkut commented 1 year ago

Fixed in 0.57.0 release, published to pypi 5/19, closing.