Skip to content

Conversation

@YuriiMotov
Copy link
Member

@YuriiMotov YuriiMotov commented Jan 28, 2026

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 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
@YuriiMotov

This comment was marked as resolved.

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

This comment was marked as resolved.

1 similar comment
@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 3, 2026
@YuriiMotov YuriiMotov marked this pull request as ready for review February 3, 2026 09:33
@YuriiMotov 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
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