I have the following code snippet
class Model(BaseModel):
is_required: float
a_float: Optional[float] = None
k: Optional[int] = None
k = Model(
**{
"is_required": 0.1,
"a_float": 1.2,
}
)
print(k.dict()) #{'is_required': 0.1, 'a_float': 1.2, 'k': None}
print(k.dict(exclude_unset=True)) #{'is_required': 0.1, 'a_float': 1.2}
This is understandable. But once I switch to SQLModel using the following code, the result changed for exclude_unset.
class Model(SQLModel):
is_required: float
a_float: Optional[float] = None
k: Optional[int] = None
k = Model(
**{
"is_required": 0.1,
"a_float": 1.2,
}
)
print(k.dict()) #{'is_required': 0.1, 'a_float': 1.2, 'k': None}
print(k.dict(exclude_unset=True)) #{'is_required': 0.1, 'a_float': 1.2, 'k': None}
Why does this happen, and is there a way for me to get a dict
where unsets are not included in the export using dict()
?