Repository: Avaiga/taipy
File: taipy/common/config/_serializer/_base_serializer.py (Python)

Code before:
                    elif dynamic_type == "int":
                        return _TemplateHandler._to_int(actual_val)
                    elif dynamic_type == "float":
                        return _TemplateHandler._to_float(actual_val)
                    elif dynamic_type == "datetime":
                        return _TemplateHandler._to_datetime(actual_val)
                    elif dynamic_type == "timedelta":
                        return _TemplateHandler._to_timedelta(actual_val)
                    elif dynamic_type == "function":
                        return _TemplateHandler._to_function(actual_val)
                    elif dynamic_type == "class":
                        return _TemplateHandler._to_class(actual_val)
                    elif dynamic_type == "str":
                        return actual_val
                    else:
                        error_msg = f"Error loading toml configuration at {val}. {dynamic_type} type is not supported."
                        raise LoadingError(error_msg)
            if isinstance(val, dict):
                return {str(k): cls._pythonify(v) for k, v in val.items()}
            if isinstance(val, list):
                return [cls._pythonify(v) for v in val]
        return val

    @classmethod
    def _timedelta_to_str(cls, obj: timedelta) -> str:
        total_seconds = obj.total_seconds()
        return (
            f"{int(total_seconds // 86400)}d"
            f"{int(total_seconds % 86400 // 3600)}h"
            f"{int(total_seconds % 3600 // 60)}m"
            f"{int(total_seconds % 60)}s"
        )


Review comment (security):
This `if` command handles the case where a dataclass instance is serialized into a dictionary.

For example, UserAttribute("email", "credential_mail", default="example@taipy.org") will be serialized to

```
{ "USER_ATTRIBUTE": {"name": "email", "credentials_name": "credentials_mail", "default": "example@taipy.org"}
```
The key is used to identify the type of the serialized object.

Code after:
                    if dynamic_type in cls._registered_types.keys():
                        return cls._registered_types[dynamic_type]._pythonify(actual_val)
                    if dynamic_type == "bool":
                        return _TemplateHandler._to_bool(actual_val)
                    elif dynamic_type == "int":
                        return _TemplateHandler._to_int(actual_val)
                    elif dynamic_type == "float":
                        return _TemplateHandler._to_float(actual_val)
                    elif dynamic_type == "datetime":
                        return _TemplateHandler._to_datetime(actual_val)
                    elif dynamic_type == "timedelta":
                        return _TemplateHandler._to_timedelta(actual_val)
                    elif dynamic_type == "function":
                        return _TemplateHandler._to_function(actual_val)
                    elif dynamic_type == "class":
                        return _TemplateHandler._to_class(actual_val)
                    elif dynamic_type == "enum":
                        return _TemplateHandler._to_enum(actual_val)
                    elif dynamic_type == "str":
                        return actual_val
                    else:
                        error_msg = f"Error loading toml configuration at {val}. {dynamic_type} type is not supported."
                        raise LoadingError(error_msg)
            if isinstance(val, dict):
                if len(val) == 1 and list(val.keys())[0] in cls._registered_types.keys():
                    return cls._registered_types[list(val.keys())[0]]._pythonify(list(val.values())[0])
                return {str(k): cls._pythonify(v) for k, v in val.items()}
            if isinstance(val, list):
                return [cls._pythonify(v) for v in val]
        return val

    @classmethod
    def _timedelta_to_str(cls, obj: timedelta) -> str:
        total_seconds = obj.total_seconds()
        return (
            f"{int(total_seconds // 86400)}d"
            f"{int(total_seconds % 86400 // 3600)}h"
            f"{int(total_seconds % 3600 // 60)}m"
            f"{int(total_seconds % 60)}s"
        )