Skip to content

Commit 1897b29

Browse files
committed
fix: validate max_training_period to disallow years and months in ForecasterParametersSchema
Signed-off-by: Mohamed Belhsan Hmida <mohamedbelhsanhmida@gmail.com>
1 parent c1df163 commit 1897b29

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

flexmeasures/data/schemas/forecasting/pipeline.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import os
55

66
from datetime import timedelta
7+
from isodate.duration import Duration
78

89
from marshmallow import (
910
fields,
@@ -196,6 +197,7 @@ def validate_parameters(self, data: dict, **kwargs):
196197
max_forecast_horizon = data.get("max_forecast_horizon")
197198
forecast_frequency = data.get("forecast_frequency")
198199
sensor = data.get("sensor")
200+
max_training_period = data.get("max_training_period")
199201

200202
if start_date is not None and end_date is not None and start_date >= end_date:
201203
raise ValidationError(
@@ -238,6 +240,14 @@ def validate_parameters(self, data: dict, **kwargs):
238240
f"forecast-frequency must be a multiple of the sensor resolution ({sensor.event_resolution})"
239241
)
240242

243+
if isinstance(max_training_period, Duration):
244+
# DurationField only returns Duration when years/months are present
245+
raise ValidationError(
246+
"max-training-period must be specified using days or smaller units "
247+
"(e.g. P365D, PT48H). Years and months are not supported.",
248+
field_name="max_training_period",
249+
)
250+
241251
@post_load
242252
def resolve_config(self, data: dict, **kwargs) -> dict: # noqa: C901
243253

0 commit comments

Comments
 (0)