pFad - Phone/Frame/Anonymizer/Declutterfier! Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

URL: http://github.com/fastapi/sqlmodel/pull/1728

assets/global-0bd78641c0a1f3e0.css" /> 🏷️ Allow `AliasChoices` and `AliasPath` for `validation_alias` in `Field` by YuriiMotov · Pull Request #1728 · fastapi/sqlmodel · GitHub
Skip to content

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

Open
YuriiMotov wants to merge 2 commits intomainfrom
validation_alias-type-hints
Open

🏷️ Allow AliasChoices and AliasPath for validation_alias in Field#1728
YuriiMotov wants to merge 2 commits intomainfrom
validation_alias-type-hints

Conversation

@YuriiMotov
Copy link
Copy Markdown
Member

@YuriiMotov YuriiMotov commented Jan 28, 2026

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

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

@github-actions github-actions bot removed the conflicts Automatically generated when a PR has a merge conflict label Feb 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

pFad - Phonifier reborn

Pfad - The Proxy pFad © 2024 Your Company Name. All rights reserved.





Check this box to remove all script contents from the fetched content.



Check this box to remove all images from the fetched content.


Check this box to remove all CSS styles from the fetched content.


Check this box to keep images inefficiently compressed and original size.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy