Skip to content

Commit 13bc7de

Browse files
committed
Backport PR #1711: Fix/schema validation in patch_asset (#1711)
* fix: patch_asset should raise a ValidationError instead of returning a tuple Signed-off-by: F.N. Claessen <felix@seita.nl> * fix: stricter error handling Signed-off-by: F.N. Claessen <felix@seita.nl> * docs: changelog entries Signed-off-by: F.N. Claessen <felix@seita.nl> --------- Signed-off-by: F.N. Claessen <felix@seita.nl> (cherry picked from commit 9cc815a) Signed-off-by: F.N. Claessen <felix@seita.nl>
1 parent d7789aa commit 13bc7de

File tree

4 files changed

+19
-6
lines changed

4 files changed

+19
-6
lines changed

documentation/api/change_log.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ API change log
55

66
.. note:: The FlexMeasures API follows its own versioning scheme. This is also reflected in the URL (e.g. `/api/v3_0`), allowing developers to upgrade at their own pace.
77

8+
v3.0-27 | 2025-09-16
9+
""""""""""""""""""""
10+
- Fix schema validation in ``PATCH /assets/<id>``.
11+
812
v3.0-26 | 2025-09-10
913
""""""""""""""""""""
1014
- Added endpoint `POST /users`.

documentation/changelog.rst

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,15 @@
33
FlexMeasures Changelog
44
**********************
55

6+
7+
v0.28.1 | September XX, 2025
8+
============================
9+
10+
Bugfixes
11+
-----------
12+
* Fix schema validation in ``PATCH /assets/(id)`` [see `PR #1711 <https://www.github.com/FlexMeasures/flexmeasures/pull/1711>`_]
13+
14+
615
v0.28.0 | September 10, 2025
716
============================
817

flexmeasures/api/v3_0/assets.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -573,7 +573,10 @@ def patch(self, asset_data: dict, id: int, db_asset: GenericAsset):
573573
:status 403: INVALID_SENDER
574574
:status 422: UNPROCESSABLE_ENTITY
575575
"""
576-
db_asset = patch_asset(db_asset, asset_data)
576+
try:
577+
db_asset = patch_asset(db_asset, asset_data)
578+
except ValidationError as e:
579+
return {"error": str(e)}, 422
577580
db.session.add(db_asset)
578581
db.session.commit()
579582
return asset_schema.dump(db_asset), 200

flexmeasures/data/services/generic_assets.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -130,11 +130,8 @@ def patch_asset(db_asset: GenericAsset, asset_data: dict) -> GenericAsset:
130130
)
131131
continue
132132
if k == "flex_context":
133-
try:
134-
# Validate the flex context schema
135-
DBFlexContextSchema().load(v)
136-
except Exception as e:
137-
return {"error": str(e)}, 422
133+
# Validate the flex context schema
134+
DBFlexContextSchema().load(v)
138135

139136
if k.lower() in {"sensors_to_show", "flex_context", "flex_model"}:
140137
audit_log_data.append(format_json_field_change(k, getattr(db_asset, k), v))

0 commit comments

Comments
 (0)