Fix serialization issue with range_spec in
TemplateField
This commit is contained in:
parent
47b006c2b0
commit
0c2d7388db
1 changed files with 7 additions and 5 deletions
|
|
@ -61,7 +61,7 @@ class TemplateField(BaseModel):
|
||||||
refresh: Optional[bool] = None
|
refresh: Optional[bool] = None
|
||||||
"""Specifies if the field should be refreshed. Defaults to False."""
|
"""Specifies if the field should be refreshed. Defaults to False."""
|
||||||
|
|
||||||
range_spec: Optional[RangeSpec] = None
|
range_spec: Optional[RangeSpec] = Field(None, serialization_alias="rangeSpec")
|
||||||
"""Range specification for the field. Defaults to None."""
|
"""Range specification for the field. Defaults to None."""
|
||||||
|
|
||||||
def to_dict(self):
|
def to_dict(self):
|
||||||
|
|
@ -73,8 +73,10 @@ class TemplateField(BaseModel):
|
||||||
return value
|
return value
|
||||||
return ""
|
return ""
|
||||||
|
|
||||||
@field_serializer("range_spec")
|
@field_serializer("field_type")
|
||||||
def serialize_range_spec(self, value):
|
def serialize_field_type(self, value, _info):
|
||||||
if self.field_type == "float" and value is None:
|
if value == "float":
|
||||||
return RangeSpec().model_dump()
|
# check if range_spec is set
|
||||||
|
if self.range_spec is None:
|
||||||
|
self.range_spec = RangeSpec()
|
||||||
return value
|
return value
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue