# sqlalchemy.orm.exc.StaleDataError: UPDATE statement on table 'users' expected to update 1 row(s); 0 were matched.

- **ID:** `python/sqlalchemy-stale-data`
- **Domain:** python
- **Category:** data_error
- **Verification:** ai_generated
- **Fix Rate:** 80%

## Root Cause

对象已被其他事务删除或修改，导致 UPDATE 操作影响行数为 0。

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| 1.4.x | active | — | — |
| 2.0.x | active | — | — |

## Workarounds

1. **** (90% success)
   ```
   在执行更新前重新查询对象，确保其存在。
   ```
2. **** (85% success)
   ```
   使用乐观锁，例如版本号字段，在更新时检查版本。
   ```

## Dead Ends

- **** — 忽略错误并继续，但数据状态不一致。 (80% fail)
- **** — 强制更新所有行，但可能覆盖其他事务的更改。 (60% fail)
