shosca / django-sorcery

Django Framework integration with SQLAlchemy
https://django-sorcery.readthedocs.io
MIT License
65 stars 6 forks source link

SQLAlchemyMiddleware does not return response #142

Closed esquonk closed 5 years ago

esquonk commented 5 years ago

SQLAlchemyMiddleware does not return response object and breaks middleware chain

        finally:
            self.return_response(request, response)

This commit appears to cause the issue.

Am I missing something here?

esquonk commented 5 years ago

I get the following error when I put django_sorcery.db.middleware.SQLAlchemyMiddleware at the top of MIDDLEWARE list.

Traceback (most recent call last):
  File "C:\Program Files\Python37\lib\wsgiref\handlers.py", line 137, in run
    self.result = application(self.environ, self.start_response)
  File "C:\Users\mi\proj\venv\flights\lib\site-packages\django\contrib\staticfiles\handlers.py", line 65, in __call__
    return self.application(environ, start_response)
  File "C:\Users\mi\proj\venv\flights\lib\site-packages\django\core\handlers\wsgi.py", line 141, in __call__
    response = self.get_response(request)
  File "C:\Users\mi\proj\venv\flights\lib\site-packages\django\core\handlers\base.py", line 76, in get_response
    response._closable_objects.append(request)
AttributeError: 'NoneType' object has no attribute '_closable_objects'
shosca commented 5 years ago

You're correct, it should return response there

shosca commented 5 years ago

Please try the fix. You can install it with pip install https://github.com/shosca/django-sorcery/archive/middleware.zip

esquonk commented 5 years ago

Thanks for the quick fix!