# Fix "'Starlette' object has no attribute 'route'" After Upgrading to Starlette 1.0

Yes. The agent replaces the removed @app.route decorators with Route entries, fixes the TemplateResponse argument order, runs the tests, and opens a pull request.

[Run this on Rush](https://cloud.getrush.ai/run/fix-starlette-object-has-no-attribute-route/starlette/). Opens the console with this prompt ready to send, in a Project that has your repository.

## What the agent does

Starlette 1.0 removed two things apps written against 0.x still use. The `@app.route` decorator is gone, so importing the module raises `AttributeError: 'Starlette' object has no attribute 'route'. Did you mean: 'router'?`. And `Jinja2Templates.TemplateResponse` no longer accepts the template name first and the context second: that order had warned since 0.29 (`The 'name' is not the first parameter anymore`) and now fails as `TypeError: unhashable type: 'dict'`. The run starts when the upgrade lands, and the agent clones the repository into its own cloud sandbox.

In a Starlette app like natanlao/yaas, `pyproject.toml` requires Python 3.14 and `starlette>=0.52.1`, and `uv.lock` holds 0.52.1, so the lock is what keeps the app working. `yaas.py` builds `app = Starlette(exception_handlers=...)` and decorates `index`, `fetch`, `fetch_json` and `robots_txt` with `@app.route`, two paths for `index`. It calls `templates.TemplateResponse` five times in the old order, including the HTTP exception handler at line 35. `tests.py` has a `SmokeTest` with `test_index` against a `TestClient`, and the Makefile's `test` target runs unittest, then `ruff format`, `ruff check` and `ty check`. The Dockerfile installs with `uv sync --locked`.

The agent reproduces the break by moving the lock: `uv lock --upgrade-package starlette` takes it to 1.10.0, `uv sync`, and `python -m unittest tests` fails at import on line 54, the first `@app.route`. It replaces the decorators with a `routes` list of `starlette.routing.Route` entries, one per path, keeping both paths for `index` and the function names as route names. Importing now works and `test_index` fails at line 56 with the `TypeError`, which is the second removal.

Each `TemplateResponse(name, {"request": request, ...})` becomes `TemplateResponse(request, name, {...})` with `request` out of the context, five calls in all. `test_index` passes on 1.10.0. The agent runs `ruff format`, `ruff check` and `ty check` as the Makefile does, and leaves `test_video` and `test_playlist` to the reviewer's note, since they fetch from Vimeo and SoundCloud and need network access the sandbox may not have.

## Start it with one API call

`POST https://api.phoenix.so/o/{org}/sessions`

```json
{
  "agent": "claude",
  "input": "Upgrade starlette to the current 1.x release in uv.lock and fix what breaks: replace the removed @app.route decorators with Route entries that keep every path and name, move the Request to the first argument of every TemplateResponse call, run the unittest suite, ruff and ty as the Makefile does, and open a pull request that quotes the AttributeError and the TypeError and lists each call you changed.",
  "resources": [
    {
      "url": "https://github.com/your-org/your-app"
    }
  ]
}
```

1. **Get an API key.** In the console, open Settings, then API keys, and create a key for your org. Send it in the Authorization header as a Bearer token.
2. **Send the request.** POST the body in request.json to https://api.phoenix.so/o/{org}/sessions, with your repository as the resources URL. The run starts in its own cloud sandbox.
3. **Read what came back.** Follow the run on its live stream or wait for the run.completed webhook, then read the result and its trajectory.

## What comes back

What comes back is a pull request that updates `uv.lock`, rewrites the routing in `yaas.py` and the five template calls, and raises the lower bound in `pyproject.toml` so a fresh lock cannot pick 0.x again. Its description quotes both errors with their line numbers and shows `test_index` passing on the new version.

A reviewer checks that every path is still served, including `/index.html` beside `/`, that `request.url_for("index")` still resolves because the route keeps its name, and that the exception handler renders `error.html` with the request. The Docker image builds from the same lock with `uv sync --locked`, so the deployed app gets exactly what the tests ran against.

If a test needs the network, the pull request says which ones ran and which were skipped in the sandbox, so the reviewer knows what proof is present and what to run on merge.

## Run it on every Monday morning

Create an automation in the Project with this prompt and a `schedule` trigger, for example `cron` set to `0 9 * * 1` in your `timezone`. Each week the run refreshes the lock, runs the suite, and opens a pull request only when something changed; a week with no new release ends with a note and no pull request.

The automation's `max_runs_per_hour` and the Project's branch rules apply as usual. A release that breaks something the agent cannot fix, such as a test that needs network access, ends in the pull request's description as an open item rather than a silent skip.

## Why run it on Rush?

A lockfile hides this break until someone regenerates it, and the two removals surface one after the other: the import error first, the template error only once the import works. A Rush run moves the lock in its own sandbox, hits both, fixes both, and keeps each traceback and the passing test in the session as the record.

Teams with several Starlette or FastAPI services face the same two edits in each. Runs go in parallel, one per repository, each with its own pull request and its own test output, and the pull request for each names the exact calls changed so review is a read, not a hunt.

## Frequently asked questions

### Does this affect FastAPI apps too?

Yes, the `TemplateResponse` change does: FastAPI's `Jinja2Templates` is Starlette's, and current FastAPI releases resolve Starlette 1.x, so the old argument order fails the same way. `@app.route` is a Starlette decorator; FastAPI's `@app.get` is unaffected.

### Why Route entries instead of app.add_route?

A `routes` list passed to `Starlette(...)` is the documented form and keeps every path visible in one place. `add_route` works too; the agent uses the list and keeps the function names as route names so `url_for` calls keep resolving.

### Can the lock stay on 0.52 and the code change later?

It can, and nothing forces the upgrade today. The pull request makes the code valid on both lines, since `Route` and the request-first `TemplateResponse` exist in 0.52.1 as well, so merging it first and moving the lock later is a safe order.

### Will ruff or ty complain about the new code?

The agent runs both as the Makefile does and fixes what they report before opening the pull request. A `ty` finding about the new `routes` list, if any, is addressed in the same change rather than left for the reviewer.

## More jobs like this: Upgrade dependencies weekly

- [Fix "TypeError: stub(obj, 'meth', fn) has been removed" After Upgrading Sinon](https://getrush.ai/run/fix-stub-obj-meth-fn-has-been-removed/sinon/)
- [Fix $.ajax(...).success Is Not a Function After a jQuery Upgrade](https://getrush.ai/run/fix-success-is-not-a-function/jquery/)
- [Fix "Textual SQL expression should be explicitly declared as text()" in SQLAlchemy 2](https://getrush.ai/run/fix-textual-sql-expression-argument-error/sqlalchemy/)
- [Fix "TypeError: this.getOptions is not a function" From sass-loader on webpack 4](https://getrush.ai/run/fix-this-getoptions-is-not-a-function/sass-loader/)
- [Fix THREE.Geometry Is Not a Constructor After a three.js Upgrade](https://getrush.ai/run/fix-three-geometry-is-not-a-constructor/three/)
- [Fix TypeScript Errors After an Upgrade](https://getrush.ai/run/fix-type-errors/nestjs/)

## Keep reading

- [How a Rush run works on your repository, from request to pull request](https://getrush.ai/cloud/)
- [Compare cloud agents, agent sandboxes and AI code review](https://getrush.ai/compare/)
- [Rush pricing: Free, Pro and Max](https://getrush.ai/pricing/)
