# Fix 'orm_mode' Has Been Renamed to 'from_attributes' in a FastAPI App

Yes. An agent reproduces the Pydantic 2 warnings in its sandbox, moves each class-based Config to model_config with from_attributes and opens a clean PR.

[Run this on Rush](https://cloud.getrush.ai/run/fix-orm-mode-has-been-renamed-to-from-attributes/pydantic/). Opens the console with this prompt ready to send, in a Project that has your repository.

## What the agent does

The agent clones the repository into its own cloud sandbox and reads the models that raise the warning. In a FastAPI app like diogoduartec/fastapi-async-sqlalchemy, `schemas.py` defines `Favorite` and `UserListOutput` with `class Config: orm_mode = True` so that `views.py` can return SQLAlchemy rows from `/user/list` with `response_model=List[UserListOutput]`; `services.py` fetches them with `select(User)` on an `AsyncSession` from `database/connection.py`, and `database/models.py` declares `User` and `Favorite` with `declarative_base()`. The `Pipfile` pins nothing: `fastapi`, `uvicorn`, `sqlalchemy`, `asyncpg`, `aiohttp`, `requests` and `psycopg2-binary` are all `"*"` under Python 3.9, and only `Pipfile.lock` holds the versions the app was written against, `fastapi` 0.70.0, `pydantic` 1.8.2, `sqlalchemy` 1.4.26, `starlette` 0.16.0. The README's setup is `docker-compose up -d` for Postgres and pgAdmin, then `pipenv install`.

It resolves the `Pipfile` fresh, which is what a new machine or a relock does, and gets `fastapi` 0.162.2 on `pydantic` 2.14.3, `sqlalchemy` 2.1.8 and `starlette` 1.10.0. `python -W default -c "import schemas"` then prints, for `Favorite` at line 22 and `UserListOutput` at line 31, `PydanticDeprecatedSince20: Support for class-based `config` is deprecated, use ConfigDict instead. Deprecated in Pydantic V2.0 to be removed in V3.0.` with a link to the migration guide, and from `pydantic/_internal/_config.py` the `UserWarning: Valid config keys have changed in V2: * 'orm_mode' has been renamed to 'from_attributes'`. Importing `main` prints the same and then stops on `ModuleNotFoundError: No module named 'greenlet'` from SQLAlchemy's async layer, a second thing the unpinned resolve changed.

The fix is mechanical and the agent keeps it that way. Each `class Config: orm_mode = True` becomes `model_config = ConfigDict(from_attributes=True)` with `ConfigDict` imported from `pydantic`, which is the Pydantic 2 spelling of the same behaviour: the response models still read attributes off SQLAlchemy rows. It imports the rewritten module with `-W error` to prove the point: no warning, and `Favorite.model_config` reads `{'from_attributes': True}`. Models without a `Config` block, `UserCreateInput`, `StandardOutput`, `ErrorOutput` and the rest, are left as they are.

It then deals with what the resolve exposed. `greenlet` is what SQLAlchemy's asyncio support needs and the `Pipfile` never named it, so the agent adds `sqlalchemy = {extras = ["asyncio"]}` (or `greenlet` directly) and relocks, and starts the app against an unreachable database URL to show the import path is clean up to the first query. It checks that `pydantic` 1.8.2 still installs on the sandbox's Python, so the pull request can say the old lock was a choice and not a constraint, and lists the version jump in the description so a reviewer knows this is a Pydantic 2 and SQLAlchemy 2 move, not only a rename.

## Start it with one API call

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

```json
{
  "agent": "claude",
  "input": "This FastAPI app prints \"UserWarning: Valid config keys have changed in V2: 'orm_mode' has been renamed to 'from_attributes'\" and \"PydanticDeprecatedSince20: Support for class-based config is deprecated\" after its dependencies were resolved against Pydantic 2. Read the dependency files and the lock, every module that defines a pydantic BaseModel, and the routes that use response_model first. Resolve the dependencies as they are declared, import the schema module with warnings enabled and quote every warning with its line. Replace each class-based Config with model_config = ConfigDict(...), mapping orm_mode to from_attributes and keeping any other key, and leave models without a Config untouched. Import the module again with warnings as errors to prove it is clean. If the resolve also exposed a missing dependency (for example greenlet for SQLAlchemy's asyncio support), add it to the declared dependencies and say so. Start the app against an unreachable database URL to show the import path is clean, run any tests, and open a pull request that quotes the warnings before and the clean import after.",
  "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 changes the two models in `schemas.py` to `model_config = ConfigDict(from_attributes=True)`, adds the `ConfigDict` import, declares the asyncio extra SQLAlchemy needs, and relocks. The description quotes the four warnings with their lines from the first import, the `ModuleNotFoundError` for `greenlet`, the clean `-W error` import after the change, and the resolved versions of `fastapi`, `pydantic`, `sqlalchemy` and `starlette` so the reviewer sees the size of the jump.

A reviewer checks the two models against the routes that return them, confirms no other model carried a `Config` block, and reads the dependency change. The run's record holds the before and after imports, so the quoted warnings can be opened as the real session.

## Run it on every terminal hand-off

You see the warnings on a fresh install and do not want to stop for them. In the console, open the Project that has the repository, paste this prompt into the composer and start it; or send this body to `POST /o/{org}/sessions` with `curl` from your terminal, with a `request_id` that is a UUID v5 of the branch name so a repeated command returns the run already started, and follow it on `GET /o/{org}/sessions/{id}/events`.

The key's `webhook_url` receives `run.completed` or `run.failed` with the session URL when the run ends, and the pull request link is on the session.

## Why run it on Rush?

The rename is one word; what you need to know is what else moved when the lock was redone, and that only shows up by resolving the dependencies in a clean environment and importing the app. The agent does that in its own sandbox, with a Python it controls, and every resolve, import and warning stays in the run's record, so the pull request names the `greenlet` gap and the SQLAlchemy 2 jump alongside the Pydantic change instead of leaving them for the next person.

It is also the kind of fix that should not wait for the person who last touched the app. Hand it off from the terminal when the warning appears, keep working, and review a small diff with the before and after imports attached, on a sandbox that was thrown away afterwards.

## Frequently asked questions

### Is from_attributes the same thing as orm_mode?

Yes. Both let a model be built from an object's attributes rather than a dict, which is how FastAPI serialises SQLAlchemy rows through `response_model`. Pydantic 2 renamed the key and moved configuration from a nested `Config` class to `model_config`; the agent makes both changes together and proves the module imports with warnings turned into errors.

### Why did the warning appear now, when the code did not change?

Because the dependencies are declared unpinned and only the lock held Pydantic 1. A fresh resolve, on a new machine or after a relock, picks up the current FastAPI, which requires Pydantic 2. The agent reproduces exactly that resolve and lists the resulting versions in the pull request.

### Can I stay on Pydantic 1 instead?

You can pin it, and the agent checks that the old version still installs so the pull request can say so. But the current FastAPI resolves to Pydantic 2 on its own, and the rename is the smaller of the two moves; the pull request takes the forward path and names the pin as the alternative.

### What is greenlet doing in this change?

SQLAlchemy's asyncio support needs it and the app's `Pipfile` never listed it, which an old lock hid. The agent's first import after the resolve stops on the missing module, so the pull request declares the asyncio extra and shows the import path clean after it.

## More Pydantic jobs

- [Fix "PydanticImportError: BaseSettings has been moved to the pydantic-settings package"](https://getrush.ai/run/fix-pydantic-basesettings-import-error/pydantic/)
- [Fix "PydanticUserError: `regex` is removed. use `pattern` instead" in Pydantic 2](https://getrush.ai/run/fix-pydantic-regex-is-removed/pydantic/)
- [Fix Pydantic V1 Style @validator Validators Are Deprecated in a FastAPI App](https://getrush.ai/run/fix-pydantic-v1-style-validator-deprecated-warning/pydantic/)

## More jobs like this: Hand off a long task

- [Fix "AttributeError: module 'scipy.misc' has no attribute 'imread'"](https://getrush.ai/run/fix-scipy-misc-imread-attribute-error/scipy/)
- [Fix "AttributeError: type object '_asyncio.Task' has no attribute 'all_tasks'" on Python 3.9 and Later](https://getrush.ai/run/fix-task-all-tasks-attribute-error/asyncio/)
- [Fix the ts-jest Config Under globals Is Deprecated Warning](https://getrush.ai/run/fix-ts-jest-config-under-globals-is-deprecated/ts-jest/)

## 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/)
