Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

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

Copy link
Copy link
@insistence

Description

@insistence
Issue body actions

Thank you for all the work you have done. I have initiated the discussion as 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": []
}

Operating System

Windows

Operating System Details

No response

FastAPI Version

0.115.0

Pydantic Version

2.9.2

Python Version

3.9.19

Additional Context

No response

jd-solanki, JoseKilo, potapov-ev, tschiolborg, mtvx and 1 more

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

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.