uvicorn.run is given the application object together with reload or workers, which need an import string

tx0/python:uvicorn-reload-app-objectdefaultwarningframeworks/fastapi-flaskdepth fastbug

What it finds

To reload on changes or to start worker processes, uvicorn imports the application again in each process, so it needs "module:app" rather than the object; with an object it prints a warning and exits. Passing the import string makes both options work.

From the rule's source, uvicorn_reload_app_object.rs.

Example from the rule's tests
import uvicornfrom fastapi import FastAPI app = FastAPI() if __name__ == "__main__":    uvicorn.run(app, reload=True)tx0 reports: uvicorn needs the app as an import string    uvicorn.run(app, workers=4)tx0 reports: uvicorn needs the app    uvicorn.run("main:app", reload=True)    uvicorn.run(app, port=8000)
Highlighted lines are the ones tx0 reports, with its message under each; the other lines are left alone.

Turn it on, off or suppress it

The rule runs in every tier. To turn it off for a project, set its level in tx0.toml:

tx0.toml
[rules]
"tx0/python:uvicorn-reload-app-object" = "off"

To keep one finding, suppress it with a reason. tx0 suppress ID --reason "..." writes the comment on the line before the code:

# tx0: ignore[tx0/python:uvicorn-reload-app-object] reason="..."

tx0 explain tx0/python:uvicorn-reload-app-object shows the same in the terminal. Found a false positive? Report it.