handle none case in state setattr (#4301)
This commit is contained in:
parent
b3c199870e
commit
1122cbf0b1
@ -1288,9 +1288,12 @@ class BaseState(Base, ABC, extra=pydantic.Extra.allow):
|
|||||||
|
|
||||||
fields = self.get_fields()
|
fields = self.get_fields()
|
||||||
|
|
||||||
if name in fields and not _isinstance(
|
if name in fields:
|
||||||
value, (field_type := fields[name].outer_type_)
|
field = fields[name]
|
||||||
):
|
field_type = field.outer_type_
|
||||||
|
if field.allow_none:
|
||||||
|
field_type = Union[field_type, None]
|
||||||
|
if not _isinstance(value, field_type):
|
||||||
console.deprecate(
|
console.deprecate(
|
||||||
"mismatched-type-assignment",
|
"mismatched-type-assignment",
|
||||||
f"Tried to assign value {value} of type {type(value)} to field {type(self).__name__}.{name} of type {field_type}."
|
f"Tried to assign value {value} of type {type(value)} to field {type(self).__name__}.{name} of type {field_type}."
|
||||||
|
Loading…
Reference in New Issue
Block a user