-1

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
  • No this does not help Commented Jan 9, 2023 at 11:15

1 Answer 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"),
):
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.