Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The debug mode does not work well #1126

Closed
2 tasks done
ghost opened this issue Jan 18, 2021 · 2 comments
Closed
2 tasks done

The debug mode does not work well #1126

ghost opened this issue Jan 18, 2021 · 2 comments

Comments

@ghost
Copy link

ghost commented Jan 18, 2021

Checklist

  • The bug is reproducible against the latest release and/or master.
  • There are no similar issues or pull requests to fix it yet.

Describe the bug

The application shows plain text instead of html page in debug mode when an error occurs.

To reproduce

I am trying to use the debug mode. Here is my application:

from starlette.applications import Starlette
from starlette.responses import JSONResponse
from starlette.routing import Route


async def show_index(request):
    return JSONResponse({'hello': current_user})


app = Starlette(debug=True, routes=[
    Route('/', show_index)])

I start the server this way:

import uvicorn

if __name__ == '__main__':
    uvicorn.run(
        'main:app', host='127.0.0.1',
        reload=True, port=5000, log_level='info')

Expected behavior

I expect an exception and the html page in my browser with debug information, but it shows plain text:
'Internal Server Error'.

Actual behavior

Browser shows plain text: 'Internal Server Error'

Debugging material

This is the traceback I see in terminal:

Traceback (most recent call last):
  File "/home/avm/workspace/abug/venv/lib/python3.9/site-packages/starlette/middleware/errors.py", line 159, in __call__
    await self.app(scope, receive, _send)
  File "/home/avm/workspace/abug/venv/lib/python3.9/site-packages/starlette/exceptions.py", line 82, in __call__
    raise exc from None
  File "/home/avm/workspace/abug/venv/lib/python3.9/site-packages/starlette/exceptions.py", line 71, in __call__
    await self.app(scope, receive, sender)
  File "/home/avm/workspace/abug/venv/lib/python3.9/site-packages/starlette/routing.py", line 582, in __call__
    await route.handle(scope, receive, send)
  File "/home/avm/workspace/abug/venv/lib/python3.9/site-packages/starlette/routing.py", line 243, in handle
    await self.app(scope, receive, send)
  File "/home/avm/workspace/abug/venv/lib/python3.9/site-packages/starlette/routing.py", line 54, in app
    response = await func(request)
  File "/home/avm/workspace/abug/main.py", line 7, in show_index
    return JSONResponse({'hello': current_user})
NameError: name 'current_user' is not defined

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/avm/workspace/abug/venv/lib/python3.9/site-packages/uvicorn/protocols/http/h11_impl.py", line 394, in run_asgi
    result = await app(self.scope, self.receive, self.send)
  File "/home/avm/workspace/abug/venv/lib/python3.9/site-packages/uvicorn/middleware/proxy_headers.py", line 45, in __call__
    return await self.app(scope, receive, send)
  File "/home/avm/workspace/abug/venv/lib/python3.9/site-packages/starlette/applications.py", line 112, in __call__
    await self.middleware_stack(scope, receive, send)
  File "/home/avm/workspace/abug/venv/lib/python3.9/site-packages/starlette/middleware/errors.py", line 165, in __call__
    response = self.debug_response(request, exc)
  File "/home/avm/workspace/abug/venv/lib/python3.9/site-packages/starlette/middleware/errors.py", line 245, in debug_response
    content = self.generate_html(exc)
  File "/home/avm/workspace/abug/venv/lib/python3.9/site-packages/starlette/middleware/errors.py", line 221, in generate_html
    traceback_obj.exc_traceback, limit  # type: ignore
AttributeError: 'TracebackException' object has no attribute 'exc_traceback'
INFO:     127.0.0.1:48170 - "GET / HTTP/1.1" 500 Internal Server Error

Environment

  • OS: Debian bullseye
  • Python version: Python 3.9.1+
  • Starlette version: starlette==0.14.1

Additional context

It looks like something bad happens in middleware/errors.py - line 221. So... Is it a bug or am I doing something wrong and illegal?

@connection-reset
Copy link

I have the same issue. exc_traceback got removed in Python 3.9 and 3.8.7 because it being there was wrong (https://bugs.python.org/issue42482).
Replacing traceback_obj.exc_traceback on line 221 with exc.__traceback__ works (it's the same object exc_traceback used to point at) but has the same issue because of which exc_traceback got removed in the first place, namely holding references.

@JayH5
Copy link
Member

JayH5 commented Feb 4, 2021

This should be fixed in Starlette 0.14.2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants