# sqlalchemy.exc.OperationalError: (psycopg2.errors.QueryCanceled) canceling statement due to user request

- **ID:** `python/sqlalchemy-query-cancelled`
- **Domain:** python
- **Category:** runtime_error
- **Verification:** ai_generated
- **Fix Rate:** 80%

## Root Cause

查询执行时间过长，触发了数据库或应用层的取消操作。

## Version Compatibility

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

## Workarounds

1. **** (80% success)
   ```
   优化查询，添加索引或减少数据量。
   ```
2. **** (75% success)
   ```
   使用 SQLAlchemy 的 execution_options 设置超时，例如：session.execute(stmt, execution_options={'timeout': 30})
   ```

## Dead Ends

- **** — 增加数据库的 statement_timeout，但可能影响其他查询。 (50% fail)
- **** — 忽略错误并重试，但可能再次超时。 (70% fail)
