Skip to content

Commit

Permalink
bug: add validator instead of using the ctor (#562)
Browse files Browse the repository at this point in the history
  • Loading branch information
MRVermeulenDeltares committed Apr 18, 2024
1 parent 9683baa commit e374f81
Showing 1 changed file with 6 additions and 10 deletions.
16 changes: 6 additions & 10 deletions hydrolib/core/dimr/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,19 +88,15 @@ class FMComponent(Component):

library: Literal["dflowfm"] = "dflowfm"

def __init__(self, **data):
super().__init__(**data)
process_input = data.get("process", None)
self.process = self._set_process_correctly(process_input)

def _set_process_correctly(self, process_input: int):
if not process_input or process_input == 0:
@validator('process', pre=True, allow_reuse=True)
def _set_process_correctly(value: int):
if not value or value == 0:
return None
if not isinstance(process_input, int):
if not isinstance(value, int):
raise ValueError(
f"Given process value {process_input}, is not of expected type {str(int)}"
f"Given process value {value}, is not of expected type {str(int)}"
)
return " ".join(str(i) for i in range(process_input))
return " ".join(str(i) for i in range(value))

@classmethod
def get_model(cls):
Expand Down

0 comments on commit e374f81

Please sign in to comment.