Query parameter models work incorrectly if fastapi-pagination enabled (FastAPI >= 0.115.0)
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:
With add_pagination:
Hi @espdev,
This is actually fastapi issue, and it's not related to fastapi-pagination. Will try to create issue on fastapi side.
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.
Hi, @uriyyo
Is there any progress on this issue?
@wu-clan I have opened PR with proposed fix - https://github.com/fastapi/fastapi/pull/12944
@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
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