Skip to content

Commit

Permalink
Override __init__ instead for pydantic data transform
Browse files Browse the repository at this point in the history
  • Loading branch information
berland committed Jan 4, 2024
1 parent c76cd42 commit 37f6583
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions src/subscript/sunsch/sunsch.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,8 @@ class SunschConfig(BaseModel):
] = None
insert: Optional[List[InsertStatement]] = None

@model_validator(mode="before")
@classmethod
def set_date_defaults(cls, config: Any) -> Any:
def __init__(self, **config):
"""Transform the input to provide defaults to required fields"""
if "startdate" not in config:
if "starttime" in config:
config["startdate"] = config["starttime"]
Expand All @@ -82,7 +81,7 @@ def set_date_defaults(cls, config: Any) -> Any:
if "refdate" not in config:
config["refdate"] = config["startdate"]

return config
super().__init__(**config)


def datetime_from_date(
Expand Down

0 comments on commit 37f6583

Please sign in to comment.