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/1730

ssets/global-0bd78641c0a1f3e0.css" /> 🏷️ Allow values that support `SupportsGt` (and others) protocol for `gt`, `ge`, `lt` and `le` in `Field` by YuriiMotov · Pull Request #1730 · fastapi/sqlmodel · GitHub
Skip to content

🏷️ Allow values that support SupportsGt (and others) protocol for gt, ge, lt and le in Field#1730

Open
YuriiMotov wants to merge 3 commits intomainfrom
gt-ge-lt-le-type-hints
Open

🏷️ Allow values that support SupportsGt (and others) protocol for gt, ge, lt and le in Field#1730
YuriiMotov wants to merge 3 commits intomainfrom
gt-ge-lt-le-type-hints

Conversation

@YuriiMotov
Copy link
Copy Markdown
Member

This PR updates type hints for gt, ge, lt, le parameters of Field to be in line with Pydantic's version:

    gt: annotated_types.SupportsGt | None = _Unset,
    ge: annotated_types.SupportsGe | None = _Unset,
    lt: annotated_types.SupportsLt | None = _Unset,
    le: annotated_types.SupportsLe | None = _Unset,

Also, added some tests for these parameters


You can currently use parameters like gt, ge, etc.. for types of fields other than int \ float:

from pydantic import ValidationError
from sqlmodel import Field, SQLModel


class Model(SQLModel):
    int_value: int = Field(gt=10)
    tuple_value: tuple[int, int] = Field(gt=(1, 2))


Model(int_value=11, tuple_value=(1, 3))

try:
    Model(int_value=10, tuple_value=(1, 3))
except ValidationError as exc_info:
    print(exc_info)

#     1 validation error for Model
# int_value
#   Input should be greater than 10 [type=greater_than, input_value=10, input_type=int]
#     For further information visit https://errors.pydantic.dev/2.12/v/greater_than


try:
    Model(int_value=11, tuple_value=(1, 2))
except ValidationError as exc_info:
    print(exc_info)

# 1 validation error for Model
# tuple_value
#   Input should be greater than (1, 2) [type=greater_than, input_value=(1, 2), input_type=tuple]
#     For further information visit https://errors.pydantic.dev/2.12/v/greater_than

... but mypy will argue:

error: No overload variant of "Field" matches argument type "tuple[int, int]"  [call-overload]

This PR fixes this

@YuriiMotov YuriiMotov added the feature New feature or request label Jan 29, 2026
@YuriiMotov YuriiMotov changed the title ✨ Allow values that support SupportsGt (and others) protocol for gt, ge, lt and le in Field 🏷️ Allow values that support SupportsGt (and others) protocol for gt, ge, lt and le in Field Jan 29, 2026
@YuriiMotov YuriiMotov marked this pull request as ready for review January 29, 2026 10:44
@github-actions github-actions bot added the conflicts Automatically generated when a PR has a merge conflict label Feb 20, 2026
@github-actions

This comment was marked as 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