fastapi-pagination icon indicating copy to clipboard operation
fastapi-pagination copied to clipboard

Query parameter models work incorrectly if fastapi-pagination enabled (FastAPI >= 0.115.0)

Open espdev opened this issue 1 year ago • 6 comments

Hello,

In FastAPI 0.115.0 query parameter models functionality has been added. If we use fastapi-pagination (add_pagination(app)) this feature works incorrectly.

For example:

class QueryFilters(BaseModel):
    foo: int | None = None
    bar: str | None = None
    baz: str | None = None

@app.get('/api')
async def api(filters: Annotated[QueryFilters, Query()]):
    return {}

Without add_pagination: image

With add_pagination: image

espdev avatar Sep 30 '24 20:09 espdev

Hi @espdev,

This is actually fastapi issue, and it's not related to fastapi-pagination. Will try to create issue on fastapi side.

uriyyo avatar Oct 04 '24 11:10 uriyyo

Did you end up creating an issue for this? If so, could you link it?

I had a look at the fastapi repo, and couldn't find an issue for this with you as an author.

Either way, I'm having the same problem. However, the problem appears when I change the return model of the specific endpoint I'm using the query parameter model. And not just because of add_pagination. If I remove the pagination from the return type, the query parameter model works fine.

YarrikV avatar Nov 04 '24 14:11 YarrikV

Hi, @uriyyo

Is there any progress on this issue?

wu-clan avatar Nov 11 '24 18:11 wu-clan

@wu-clan I have opened PR with proposed fix - https://github.com/fastapi/fastapi/pull/12944

uriyyo avatar Nov 16 '24 11:11 uriyyo

@YarrikV Sorry, I had no time to create issue.

I opened PR with proposed fix, you can take a look here - https://github.com/fastapi/fastapi/pull/12944

uriyyo avatar Nov 16 '24 11:11 uriyyo

Hi all (@espdev, @wu-clan, @YarrikV)

I created a library called fastapi-backports, and it contains backports for fastapi features that already have a fix.

It contains a fix for this issue.

You need to install fastapi-backports package and add following line to one on your root modules, it should be added before fastapi imports:

import fastapi_backports.apply  # noqa: F401

Link to repo - https://github.com/uriyyo/fastapi-backports

uriyyo avatar Oct 05 '25 13:10 uriyyo