Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix premature flex context deserialization #593

Merged
merged 5 commits into from Feb 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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