python - FastAPI SQLAlchemy 无法将字典更新序列元素 #0 转换为序列

标签 python sqlalchemy fastapi

我正在尝试返回操作列表并收到错误

@router.get("/")
async def get_specific_operations(operation_type: str, session: AsyncSession = Depends(get_async_session)):
    query = select(operation).where(operation.c.type == operation_type)
    result = await session.execute(query)
    return result.all()

错误:

ValueError: [TypeError('cannot convert dictionary update sequence element #0 to a sequence'), TypeError('vars() argument must have __dict__ attribute')]

最佳答案

尝试代替 result.all() 来执行此操作 result.scalars().all()

关于python - FastAPI SQLAlchemy 无法将字典更新序列元素 #0 转换为序列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/76322342/

相关文章:

python - 为什么我会收到 CORS 错误原因 : CORS request did not succeed

python - Java Spring Boot 与 Python FastApi : Threads

python - Paramiko scp 从远程机器正则表达式复制

python - Pandas Python - 对其他人进行分组计数

Flask SQLAlchemy 设置 expire_on_commit=False

python - 是否可以从 psycopg2 或 sqlalchemy 为 PostgreSQL 发出 "VACUUM ANALYZE <tablename>"?

python - 如何在 FastAPI 中验证请求正文?

python - 具有透明背景的 Qt 小部件

python - 如何使用对齐的空格字符将 python pandas.DataFrame 写入文件?

python - 分配给子关系时避免在冲洗后选择