Closed euri10 closed 1 year ago
when using starsessions, excellent middleware btw :), there is a bug when trying to render the template, here is the trace
starsessions
backend-1 | ERROR: Exception in ASGI application backend-1 | Traceback (most recent call last): backend-1 | File "/opt/venv/lib/python3.10/site-packages/uvicorn/protocols/http/httptools_impl.py", line 401, in run_asgi backend-1 | result = await app(self.scope, self.receive, self.send) backend-1 | File "/opt/venv/lib/python3.10/site-packages/uvicorn/middleware/proxy_headers.py", line 78, in __call__ backend-1 | return await self.app(scope, receive, send) backend-1 | File "/opt/venv/lib/python3.10/site-packages/uvicorn/middleware/message_logger.py", line 86, in __call__ backend-1 | raise exc from None backend-1 | File "/opt/venv/lib/python3.10/site-packages/uvicorn/middleware/message_logger.py", line 82, in __call__ backend-1 | await self.app(scope, inner_receive, inner_send) backend-1 | File "/opt/venv/lib/python3.10/site-packages/fastapi/applications.py", line 269, in __call__ backend-1 | await super().__call__(scope, receive, send) backend-1 | File "/opt/venv/lib/python3.10/site-packages/starlette/applications.py", line 124, in __call__ backend-1 | await self.middleware_stack(scope, receive, send) backend-1 | File "/opt/venv/lib/python3.10/site-packages/starlette/middleware/errors.py", line 184, in __call__ backend-1 | raise exc backend-1 | File "/opt/venv/lib/python3.10/site-packages/starlette/middleware/errors.py", line 162, in __call__ backend-1 | await self.app(scope, receive, _send) backend-1 | File "/opt/venv/lib/python3.10/site-packages/starsessions/middleware.py", line 86, in __call__ backend-1 | await self.app(scope, receive, send_wrapper) backend-1 | File "/opt/venv/lib/python3.10/site-packages/starception/middleware.py", line 44, in __call__ backend-1 | response = self.debug_response(request, exc) backend-1 | File "/opt/venv/lib/python3.10/site-packages/starception/middleware.py", line 57, in debug_response backend-1 | return exception_handler(request, exc) backend-1 | File "/opt/venv/lib/python3.10/site-packages/starception/exception_handler.py", line 111, in exception_handler backend-1 | content = generate_html(request, exc) backend-1 | File "/opt/venv/lib/python3.10/site-packages/starception/exception_handler.py", line 126, in generate_html backend-1 | return template.render( backend-1 | File "/opt/venv/lib/python3.10/site-packages/jinja2/environment.py", line 1301, in render backend-1 | self.environment.handle_exception() backend-1 | File "/opt/venv/lib/python3.10/site-packages/jinja2/environment.py", line 936, in handle_exception backend-1 | raise rewrite_traceback_stack(source=source) backend-1 | File "/opt/venv/lib/python3.10/site-packages/starception/templates/index.html", line 41, in top-level template code backend-1 | {{ lib.details_row('Session', session) }} backend-1 | File "/opt/venv/lib/python3.10/site-packages/jinja2/runtime.py", line 777, in _invoke backend-1 | rv = self._func(*arguments) backend-1 | File "/opt/venv/lib/python3.10/site-packages/starception/templates/lib.html", line 4, in template backend-1 | {% for label, value in items|items %} backend-1 | File "/opt/venv/lib/python3.10/site-packages/jinja2/filters.py", line 246, in do_items backend-1 | raise TypeError("Can only get item pairs from a mapping.") backend-1 | TypeError: Can only get item pairs from a mapping.
the fix is simple and could happen here using request.session.data instead of request.session https://github.com/alex-oleshkevich/starception/blob/c8030d9f62b63cfd437364e02a27ed0342d938e2/starception/exception_handler.py#L157 but this wont be compatible with the default Starlette SessionMiddleware, so I'm not sure if this shouldn't be handled upstream in starsessions or if starception could detect the use of a custom middleware for sessions ;)
request.session.data
Fixed in #6
marvelous ! and way simpler fix, thanks !!
when using
starsessions
, excellent middleware btw :), there is a bug when trying to render the template, here is the tracethe fix is simple and could happen here using
request.session.data
instead of request.session https://github.com/alex-oleshkevich/starception/blob/c8030d9f62b63cfd437364e02a27ed0342d938e2/starception/exception_handler.py#L157 but this wont be compatible with the default Starlette SessionMiddleware, so I'm not sure if this shouldn't be handled upstream in starsessions or if starception could detect the use of a custom middleware for sessions ;)