Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

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

starlette < 0.17.0 doesn't give exception tracebacks when testing app #4154

Closed
9 tasks done
kevr opened this issue Nov 6, 2021 · 4 comments
Closed
9 tasks done

starlette < 0.17.0 doesn't give exception tracebacks when testing app #4154

kevr opened this issue Nov 6, 2021 · 4 comments
Labels
question Question or problem question-migrate

Comments

@kevr
Copy link

kevr commented Nov 6, 2021

First Check

  • I added a very descriptive title to this issue.
  • I used the GitHub search to find a similar issue and didn't find it.
  • I searched the FastAPI documentation, with the integrated search.
  • I already searched in Google "How to X in FastAPI" and didn't find any information.
  • I already read and followed all the tutorial in the docs and didn't find an answer.
  • I already checked if it is not related to FastAPI but to Pydantic.
  • I already checked if it is not related to FastAPI but to Swagger UI.
  • I already checked if it is not related to FastAPI but to ReDoc.

Commit to Help

  • I commit to help with one of those options 👆

Example Code

# asgi app definition
from fastapi import FastAPI, Request

app = FastAPI()

@app.get("/")
async def root(request: Request):
    raise Exception("Blah blah")

# pytest unit
import pytest

from fastapi.testclient import TestClient

from .asgi import app

@pytest.fixture
def client() -> TestClient:
    yield TestClient(app=app)

def test_app(client: TestClient):
    with client as request:
        response = request.get("/")
    assert response.status_code == 200

Description

Run the pytest suite, an exception is raised, causing a nonsensical traceback. This nonsensical traceback is generated by starlette==0.16.0.

It has been resolved in starlette==0.17.0 partially; enough that we actual get information about the original exception. FastAPI has not yet however released a version which depends on starlette==0.17.0, meaning we cannot yet use it through Python package managers which depend on version resolution.

If you run the aforementioned example, you will see exactly what I mean. You end up getting exceptions purely about anyio failing and not the original exception; essentially hiding the real cause of the test failure.

It currently emits a RuntimeError("No response returned.")

Operating System

Linux

Operating System Details

Arch Linux

FastAPI Version

0.70.0

Python Version

3.9.5

Additional Context

No response

@kevr kevr added the question Question or problem label Nov 6, 2021
@kevr kevr changed the title [Bug] starlette < 0.17.0 doesn't give tracebacks when testing app [Bug] starlette < 0.17.0 doesn't give exception tracebacks when testing app Nov 6, 2021
@ehiggs
Copy link

ehiggs commented Nov 7, 2021

This will be solved by #4145

@yezz123
Copy link
Contributor

yezz123 commented Nov 7, 2021

Downgrade your starlette version or wait until #4145 being merged to fix this issue

@Kludex
Copy link
Sponsor Collaborator

Kludex commented Nov 7, 2021

You can also pin the commit/branch on your requirements i.e. https://stackoverflow.com/a/13754517

For simple install, you can do: python -m pip install git+git://github.com/simondale00/fastapi.git@upgrade-starlette-0.17.0

But better to fork and apply your own changes rather than using third-party branches, jfyk.

@kevr
Copy link
Author

kevr commented Nov 9, 2021

Ahh, gotcha. Sorry, I tried searching, but guess I searched incorrectly there.

Thanks guys!

@kevr kevr closed this as completed Nov 9, 2021
@tiangolo tiangolo changed the title [Bug] starlette < 0.17.0 doesn't give exception tracebacks when testing app starlette < 0.17.0 doesn't give exception tracebacks when testing app Feb 24, 2023
@tiangolo tiangolo reopened this Feb 27, 2023
Repository owner locked and limited conversation to collaborators Feb 27, 2023
@tiangolo tiangolo converted this issue into discussion #6433 Feb 27, 2023

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Labels
question Question or problem question-migrate
Projects
None yet
Development

No branches or pull requests

5 participants