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

🏷️ Fix typing for `exclude` parameter of `Field`, deprecate `include` parameter by YuriiMotov · Pull Request #1724 · fastapi/sqlmodel · GitHub

Repository navigation

🏷️ Fix typing for exclude parameter of Field, deprecate include parameter - #1724

Open
YuriiMotov wants to merge 9 commits into
mainfrom
fix-field-exclude-parameter-typing
Open

YuriiMotov wants to merge 9 commits into
mainfrom
fix-field-exclude-parameter-typing

Conversation

YuriiMotov commented Jan 28, 2026 •
edited
Loading

Copy link
Copy Markdown
Member

The type of exclude parameter is just bool | None in Pydantic V2, set and dict are not allowed anymore (sources).

from pydantic import BaseModel, Field

class User(BaseModel):
    id: int
    username: str

class Transaction(BaseModel):
    id: str
    user: User = Field(..., exclude={'username'})

user = User(id=1, username='alice')
transaction = Transaction(id='txn_123', user=user)

print(transaction.model_dump())

# pydantic_core._pydantic_core.SchemaError: Error building `model` serializer:
#   SchemaError: Error building `model-fields` serializer:
#   TypeError: 'set' object cannot be converted to 'PyBool'

I updated type hint and added a simple test for this parameter.


I also deprecated the include parameter as it's useless (doesn't do anything) in Pydantic V2.

From Pydantic sources:

    include = extra.pop('include', None)  # type: ignore
    if include is not None:
        warn(
            '`include` is deprecated and does nothing. It will be removed, use `exclude` instead',
            PydanticDeprecatedSince20,
            stacklevel=2,
        )

YuriiMotov changed the title 🏷️ Fix typing for exclude parameter to Field, removed include parameter 🏷️ Fix typing for exclude parameter of Field, remove include parameter Jan 28, 2026

This comment was marked as resolved.

YuriiMotov marked this pull request as draft January 31, 2026 23:33
github-actions Bot added the conflicts Automatically generated when a PR has a merge conflict label Feb 1, 2026

This comment was marked as resolved.

1 similar comment

This comment was marked as resolved.

github-actions Bot removed the conflicts Automatically generated when a PR has a merge conflict label Feb 3, 2026
YuriiMotov marked this pull request as ready for review February 3, 2026 09:33
YuriiMotov changed the title 🏷️ Fix typing for exclude parameter of Field, remove include parameter 🏷️ Fix typing for exclude parameter of Field, deprecate include parameter Feb 3, 2026
github-actions Bot added the conflicts Automatically generated when a PR has a merge conflict label Feb 20, 2026

This comment was marked as 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 Apr 3, 2026

This comment was marked as resolved.

github-actions Bot removed the conflicts Automatically generated when a PR has a merge conflict label Apr 3, 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.

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

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants


Back | FazBrowse Home | New Git URL