英文:
Get multiple items given an arbitrary query -> Python FastAPi
问题
获取多个项目的任意查询。我正在尝试使用Python Fastapi实现这一目标,这是我在路由中所做的事情:
def get_props_query(
*,
session: Session = Depends(get_session),
query: Optional[Props] = Query(
default=select(PropsTable), description="它是可选的"
)):
但是出现以下错误:
raise fastapi.exceptions.FastAPIError(
fastapi.exceptions.FastAPIError: 响应字段的参数无效!提示:检查 typing.Optional
创建了这样的模型:
from pydantic import BaseModel
class Props(BaseModel):
query: Optional[str]
英文:
Get multiple items given an arbitrary query. I am trying to achieve this using Python Fastapi, this is what I did in routes,
def get_props_query(
*,
session: Session = Depends(get_session),
query: Optional[Props] = Query(
default=select(PropsTable), description="It is optional"
)):
but getting this error ->
raise fastapi.exceptions.FastAPIError(
fastapi.exceptions.FastAPIError: Invalid args for response field! Hint: check that typing.Optional
Created a model like this
from pydantic import BaseModel
class Props(BaseModel):
query: Optional[str]
答案1
得分: 0
这部分内容的翻译如下:
"这个部分的翻译如下:
Well this worked fine, I wanted to pass RAW SQL query from FastAPI swagger UI.
This is what I done in the routes
def get_props_query(
*,
session: Session = Depends(get_session),
query: Union[str, None] = Query(default=None, description="It is optional"),
):
英文:
Well this worked fine, I wanted to pass RAW SQL query from FastAPI swagger UI.
This is what I done in the routes
def get_props_query(
*,
session: Session = Depends(get_session),
query: Union[str, None] = Query(default=None, description="It is optional"),
):
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论