Skip to content

Commit

Permalink
feat: validate attribute before storing
Browse files Browse the repository at this point in the history
Signed-off-by: F.N. Claessen <felix@seita.nl>
  • Loading branch information
Flix6x committed Sep 15, 2023
1 parent 3305027 commit fc8ebe8
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
4 changes: 4 additions & 0 deletions flexmeasures/cli/data_edit.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

from flexmeasures import Sensor
from flexmeasures.data import db
from flexmeasures.data.schemas.attributes import validate_special_attributes
from flexmeasures.data.schemas.generic_assets import GenericAssetIdField
from flexmeasures.data.schemas.sensors import SensorIdField
from flexmeasures.data.models.generic_assets import GenericAsset
Expand Down Expand Up @@ -129,6 +130,9 @@ def edit_attribute(
attribute_null_value=attribute_null_value,
)

# Some attributes with special in meaning in FlexMeasures must pass validation
validate_special_attributes(attribute_key, attribute_value)

# Set attribute
for asset in assets:
asset.attributes[attribute_key] = attribute_value
Expand Down
9 changes: 9 additions & 0 deletions flexmeasures/data/schemas/attributes.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from typing import Any

from altair.vegalite.schema import Interpolate


def validate_special_attributes(key: str, value: Any):
"""Validate attributes with a special meaning in FlexMeasures."""
if key == "interpolate":
Interpolate.validate(value)

0 comments on commit fc8ebe8

Please sign in to comment.