From d6996253b27ab3b80ad7f5dab09810492455dfe9 Mon Sep 17 00:00:00 2001 From: Bohdan Bobrowski Date: Fri, 20 Dec 2024 10:15:51 +0100 Subject: [PATCH] Fixing tuple in yaml bug --- blog2epub/common/settings.py | 5 +---- blog2epub/models/configuration.py | 6 +++++- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/blog2epub/common/settings.py b/blog2epub/common/settings.py index 97d0770..f86e40e 100644 --- a/blog2epub/common/settings.py +++ b/blog2epub/common/settings.py @@ -54,8 +54,5 @@ def save(self, data: ConfigurationModel | None = None): data = self.data data = self._save_history(data) with open(self.settings_file, "w") as outfile: - try: - data_dict = data.model_dump() - except AttributeError: - data_dict = data.dict() + data_dict = data.model_dump() yaml.dump(data_dict, outfile, default_flow_style=False) diff --git a/blog2epub/models/configuration.py b/blog2epub/models/configuration.py index bbc2343..20a0952 100644 --- a/blog2epub/models/configuration.py +++ b/blog2epub/models/configuration.py @@ -2,7 +2,7 @@ from dataclasses import field from pathlib import Path -from pydantic import BaseModel +from pydantic import BaseModel, field_serializer example_blogs = [ "http://archaia-ellada.blogspot.com", @@ -49,6 +49,10 @@ class ConfigurationModel(BaseModel): email: str = "" version: str = "" + @field_serializer("images_size") + def serialize_images_size(self, images_size: tuple[int, int], _info): + return [images_size[0], images_size[1]] + def __init__(self, **kwargs) -> None: super().__init__(**kwargs) if self.url == "":