Skip to content

Commit

Permalink
Fix premature flex context deserialization (#593)
Browse files Browse the repository at this point in the history
* Test flex-context deserialization

Signed-off-by: F.N. Claessen <felix@seita.nl>

* Fix flex-context deserialization

Signed-off-by: F.N. Claessen <felix@seita.nl>

* black

Signed-off-by: F.N. Claessen <felix@seita.nl>

* flake8

Signed-off-by: F.N. Claessen <felix@seita.nl>

* Changelog entries

Signed-off-by: F.N. Claessen <felix@seita.nl>

---------

Signed-off-by: F.N. Claessen <felix@seita.nl>
  • Loading branch information
Flix6x committed Feb 27, 2023
1 parent 08241ca commit c02469a
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 5 deletions.
5 changes: 5 additions & 0 deletions documentation/api/change_log.rst
Expand Up @@ -5,6 +5,11 @@ API change log

.. note:: The FlexMeasures API follows its own versioning scheme. This is also reflected in the URL, allowing developers to upgrade at their own pace.

v3.0-7 | 2023-02-27
"""""""""""""""""""

- Fix premature deserialization of ``flex-context`` field for `/sensors/<id>/schedules/trigger` (POST).

v3.0-6 | 2023-02-01
"""""""""""""""""""

Expand Down
9 changes: 9 additions & 0 deletions documentation/changelog.rst
Expand Up @@ -22,6 +22,15 @@ Infrastructure / Support
* Sunset several API fields for `/sensors/<id>/schedules/trigger` (POST) that have moved into the ``flex-model`` or ``flex-context`` fields [see `PR #580 <https://www.github.com/FlexMeasures/flexmeasures/pull/580>`_]


v0.12.3 | February 27, 2023
============================

Bugfixes
-----------

- Fix premature deserialization of ``flex-context`` field for `/sensors/<id>/schedules/trigger` (POST) [see `PR #593 <https://www.github.com/FlexMeasures/flexmeasures/pull/593>`_]


v0.12.2 | February 4, 2023
============================

Expand Down
5 changes: 1 addition & 4 deletions flexmeasures/api/v3_0/sensors.py
Expand Up @@ -33,7 +33,6 @@
from flexmeasures.data.queries.utils import simplify_index
from flexmeasures.data.schemas.sensors import SensorSchema, SensorIdField
from flexmeasures.data.schemas.times import AwareDateTimeField, PlanningDurationField
from flexmeasures.data.schemas.scheduling import FlexContextSchema
from flexmeasures.data.services.sensors import get_sensors
from flexmeasures.data.services.scheduling import (
create_scheduling_job,
Expand Down Expand Up @@ -205,9 +204,7 @@ def get_data(self, response: dict):
load_default=PlanningDurationField.load_default
),
"flex_model": fields.Dict(data_key="flex-model"),
"flex_context": fields.Nested(
FlexContextSchema, required=False, data_key="flex-context"
),
"flex_context": fields.Dict(required=False, data_key="flex-context"),
},
location="json",
)
Expand Down
8 changes: 8 additions & 0 deletions flexmeasures/api/v3_0/tests/test_sensor_schedules.py
Expand Up @@ -90,6 +90,14 @@ def test_trigger_and_get_schedule(
message,
asset_name,
):

# Include the price sensor in the flex-context explicitly, to test deserialization
price_sensor_id = add_market_prices["epex_da"].id
message["flex-context"] = {
"consumption-price-sensor": price_sensor_id,
"production-price-sensor": price_sensor_id,
}

# trigger a schedule through the /sensors/<id>/schedules/trigger [POST] api endpoint
assert len(app.queues["scheduling"]) == 0

Expand Down
5 changes: 4 additions & 1 deletion flexmeasures/conftest.py
Expand Up @@ -491,7 +491,9 @@ def create_beliefs(db: SQLAlchemy, setup_markets, setup_sources) -> int:


@pytest.fixture(scope="module")
def add_market_prices(db: SQLAlchemy, setup_assets, setup_markets, setup_sources):
def add_market_prices(
db: SQLAlchemy, setup_assets, setup_markets, setup_sources
) -> Dict[str, Sensor]:
"""Add two days of market prices for the EPEX day-ahead market."""

# one day of test data (one complete sine curve)
Expand Down Expand Up @@ -533,6 +535,7 @@ def add_market_prices(db: SQLAlchemy, setup_assets, setup_markets, setup_sources
for dt, val in zip(time_slots, values)
]
db.session.add_all(day2_beliefs)
return {"epex_da": setup_markets["epex_da"].corresponding_sensor}


@pytest.fixture(scope="module")
Expand Down

0 comments on commit c02469a

Please sign in to comment.