Skip to content

Serializer for extra fields not used #12385

@Viicos

Description

@Viicos

From https://github.com/pydantic/pydantic-core/pull/1835/files#r2425738743:

from pydantic import BaseModel

class Model(BaseModel, extra='allow'):
    a: int
    __pydantic_extra__: dict[str, int]


m = Model(a=1, extra=1)
m.a = 'not_an_int'
m.model_dump_json()  # PydanticSerializationUnexpectedValue warning raised

m.a = 1
m.extra = 'not_an_int'
m.model_dump_json()  # No warning raised

Also https://github.com/pydantic/pydantic-core/pull/1835/files#r2425737760 should probably be supported.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug V2Bug related to Pydantic V2

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions