FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

🏷️ Allow `AliasChoices` and `AliasPath` for `validation_alias` in `Field` by YuriiMotov · Pull Request #1728 · fastapi/sqlmodel · GitHub

Repository navigation

🏷️ Allow AliasChoices and AliasPath for validation_alias in Field - #1728

Open
YuriiMotov wants to merge 2 commits into
mainfrom
validation_alias-type-hints
Open

YuriiMotov wants to merge 2 commits into
mainfrom
validation_alias-type-hints

Conversation

YuriiMotov commented Jan 28, 2026 •
edited
Loading

Copy link
Copy Markdown
Member

This PR updates type hints for validation_alias parameter of Field to be in line with Pydantic's version:

    validation_alias: str | AliasPath | AliasChoices | None = _Unset,

Also, added tests for AliasPath and AliasChoices


The following code works on master:

from typing import Optional

from pydantic import AliasChoices, AliasPath
from sqlmodel import Field, SQLModel


class User(SQLModel):
    first_name: str = Field(validation_alias="firstName", serialization_alias="f_name")
    second_name: Optional[str] = Field(
        default=None, validation_alias=AliasChoices("secondName", "surname")
    )
    nickname: Optional[str] = Field(
        default=None, validation_alias=AliasPath("names", 2)
    )


test_data = [
    {"firstName": "John", "secondName": "Doe", "names": ["John", "Doe", "Johnny"]},
    {"firstName": "John", "surname": "Doe", "names": ["John", "Doe", "Johnny"]},
]


for data in test_data:
    print(User.model_validate(data))

# first_name='John' second_name='Doe' nickname='Johnny'
# first_name='John' second_name='Doe' nickname='Johnny'

.. but mypy argues with:

main.py:9: error: No overload variant of "Field" matches argument types "None", "AliasChoices"  [call-overload]
main.py:12: error: No overload variant of "Field" matches argument types "None", "AliasPath"  [call-overload]

This PR fixes this.

YuriiMotov marked this pull request as ready for review January 28, 2026 21:02
YuriiMotov added feature New feature or request and removed refactor labels Jan 29, 2026
YuriiMotov force-pushed the validation_alias-type-hints branch from 63578da to b15644e Compare January 29, 2026 09:32
github-actions Bot added the conflicts Automatically generated when a PR has a merge conflict label Feb 20, 2026

Copy link
Copy Markdown
Contributor

This pull request has a merge conflict that needs to be resolved.

github-actions Bot removed the conflicts Automatically generated when a PR has a merge conflict label Feb 20, 2026
github-actions Bot added the conflicts Automatically generated when a PR has a merge conflict label Aug 28, 2026

Copy link
Copy Markdown
Contributor

This pull request has a merge conflict that needs to be resolved.

This branch has not been deployed

No deployments
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

conflicts Automatically generated when a PR has a merge conflict feature New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants


Back | FazBrowse Home | New Git URL