Skip to content

Junie [BUG] In version 0.115.0 of FastAPI, the pydantic model that has declared an alias cannot correctly receive query parameters #5

@AlexanderPrendota

Description

@AlexanderPrendota

Privileged issue

  • I'm @tiangolo or he asked me directly to create an issue here.

Issue Content

Thank you for all the work you have done. I have initiated the https://github.com/fastapi/fastapi/discussions/12401as requested, but I think this issue is quite important. Initiating this issue is just to prevent the discussion from being drowned out, and I apologize for any offense.

Example Code
import uvicorn
from typing import Literal

from fastapi import FastAPI, Query
from pydantic import BaseModel, ConfigDict, Field
from pydantic.alias_generators import to_camel

app = FastAPI()

class FilterParams(BaseModel):
model_config = ConfigDict(alias_generator=to_camel)

limit: int = Field(100, gt=0, le=100)
offset: int = Field(0, ge=0)
order_by: Literal['created_at', 'updated_at'] = 'created_at'
tags: list[str] = []

@app.get('/items/')
async def read_items(filter_query: FilterParams = Query()):
return filter_query

if name == 'main':
uvicorn.run(app='app:app')
Description
Running the code in the example above, I encountered an incorrect result when accessing http://127.0.0.1:8000/items/?offset=1&orderBy=updated_at in the browser, orderBy did not receive successfully.

{
"limit": 100,
"offset": 1,
"orderBy": "created_at",
"tags": []
}
The correct result should be as follows

{
"limit": 100,
"offset": 1,
"orderBy": "updated_at",
"tags": []
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions