Fix serialization issue with range_spec in

TemplateField
This commit is contained in:
Gabriel Luiz Freitas Almeida 2023-12-10 16:48:24 -03:00
commit 0c2d7388db

View file

@ -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