Skip to content

Commit

Permalink
core:libs:commonwealth:Unify dump in pydantic save
Browse files Browse the repository at this point in the history
* Change to use in both older and newer pydantic versions dict with
  json.dumps instead of using write directly
  • Loading branch information
JoaoMario109 authored and patrickelectric committed Nov 18, 2024
1 parent 7cb34fb commit f776c91
Showing 1 changed file with 3 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

from loguru import logger
from pydantic import BaseModel, ValidationError
from pydantic import __version__ as pydantic_version

from commonwealth.settings.exceptions import (
BadAttributes,
Expand Down Expand Up @@ -100,11 +99,9 @@ def save(self, file_path: pathlib.Path) -> None:

with open(file_path, "w", encoding="utf-8") as settings_file:
logger.debug(f"Saving settings on: {file_path}")
if pydantic_version > "1.8.0":
json_data = self.dict()
json.dump(json_data, settings_file, indent=4)
else:
settings_file.write(self.json(indent=4))

json_data = self.dict()
json.dump(json_data, settings_file, indent=4)

def reset(self) -> None:
"""Reset internal data to default values"""
Expand Down

0 comments on commit f776c91

Please sign in to comment.