Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Boolean query params #27

Open
butvinm opened this issue Mar 12, 2023 · 2 comments
Open

Boolean query params #27

butvinm opened this issue Mar 12, 2023 · 2 comments
Labels
bug Something isn't working

Comments

@butvinm
Copy link

butvinm commented Mar 12, 2023

Describe the bug
Boolean cannot be used in query params

Example

async def get_users(
    offset: Optional[int] = None,
    count: Optional[int] = None,
    status: UserStatus = None,
    chat_id: Optional[int] = None,
    include_deleted: Optional[bool] = None,
    api_config_override: Optional[APIConfig] = None,
) -> UsersResponse:
    api_config = api_config_override if api_config_override else APIConfig()

    base_path = api_config.base_path
    path = f"/api/users/"
    headers = {
        "Content-Type": "application/json",
        "Accept": "application/json",
        "x-api-key": api_config.get_access_token(),
    }

    query_params: Dict[str, Any] = {
        "offset": offset,
        "count": count,
        "status": status,
        "chat_id": chat_id,
        "include_deleted": str(include_deleted),
    }

    query_params = {key: value for (key, value) in query_params.items() if value is not None}

    async with aiohttp.ClientSession(headers=headers) as session:
        async with session.request(
            "get",
            base_path + path,
            params=query_params,
        ) as inital_response:
            if inital_response.status != 200:
                raise HTTPException(inital_response.status, f" failed with status code: {inital_response.status}")
            response = await inital_response.json()

            return UsersResponse(**response) if response is not None else UsersResponse()

TypeError("Invalid variable type: value should be str, int or float, got True of type <class 'bool'>") is raised if call like await get_users(chat_id=message.chat.id, include_deleted=True)

Expected behavior
You can convert boolean params to strings before sending request

@MarcoMuellner
Copy link
Owner

Please provide a openapi.json file for this to test :)

@MarcoMuellner MarcoMuellner added the bug Something isn't working label Mar 14, 2023
@butvinm
Copy link
Author

butvinm commented Mar 14, 2023

https://flawcontrolsystem-1-s9590805.deta.app/openapi.json

get_users route, include_deleted param

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants