Skip to content

model_validate fails to work correctly under multiple inheritance #12229

@xdewx

Description

@xdewx

Initial Checks

  • I confirm that I'm using Pydantic V2

Description

code is at the below, my question it not work.

        x = Xxx.model_validate(dict(quantity=10, xxx="m"))
        assert x.unit == "m"

Example Code

from pydantic import BaseModel
import pytest

class QuantifiedValue(BaseModel):
    unit: int
    quantity: int

class OverideQuantifiedValue(QuantifiedValue):

    unit: str = Field(validation_alias=AliasChoices("xxx"))


class Xxx(OverideQuantifiedValue):
    pass


Yyy = OverideQuantifiedValue


def test_override_quantified_value():
    x = OverideQuantifiedValue.model_validate(dict(quantity=10, xxx="m"))
    assert x.unit == "m"

    with pytest.raises(AssertionError):

        x = Xxx.model_validate(dict(quantity=10, xxx="m"))
        assert x.unit == "m"

    y = Yyy.model_validate(dict(quantity=10, xxx="m"))
    assert y.unit == "m"

Python, Pydantic & OS Version

pydantic version: 2.11.7
        pydantic-core version: 2.33.2
          pydantic-core build: profile=release pgo=false
               python version: 3.13.5 | packaged by Anaconda, Inc. | (main, Jun 12 2025, 16:37:03) [MSC v.1929 64 bit (AMD64)]
                     platform: Windows-11-10.0.26100-SP0
             related packages: typing_extensions-4.14.0 typing_extensions-4.14.1
                       commit: unknown

Metadata

Metadata

Assignees

No one assigned

    Labels

    awaiting author responseawaiting response from issue openerbug V2Bug related to Pydantic V2pendingIs unconfirmed

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions