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 removed 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,
        )

I think we can do it without deprecation step as it hasn't been working for a wile already and people who tried using it saw deprecation warning from Pydantic

@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
Copy link
Member Author

I probably need to make this consistent with another PR that addresses parameters removed in Pydantic V2: in this PR I deleted fields, but in another PR I deprecated them

@YuriiMotov YuriiMotov marked this pull request as draft January 31, 2026 23:33
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