The title says it all:
Why does my Pydantic model contain an extra attribute when popupated from an object with extra=ignore?
from pydantic import BaseModel, ConfigDict
# pydantic 2.4.2
class Test(BaseModel):
a: int
model_config = ConfigDict(extra='ignore',
from_attributes=True)
class TestExtended(Test):
b: float
m = TestExtended(a=2, b=2)
# Why does m_1 contain the additional field "b" even though
# we try to instantiate Test with extra=ignore?
m_1 = Test.model_validate(m)
print(m_1)
The output shows that the model contains both attributes:
>>> a=2 b=2.0
Any ideas what the reason for this behaviour is?