From 3fb80a9499cb85285b4a1aa8d4846716d62dd1ec Mon Sep 17 00:00:00 2001 From: "Mathias L. Baumann" Date: Wed, 17 Apr 2024 18:15:54 +0200 Subject: [PATCH] Make `Client.update` require named parameters I noticed it happened often that I used the microgrid id instead of the dispatch id to identify the to-be-updated dispatch which of course is wrong. This should make it more obvious when using the API what kind of ID should be passed. Optimally we have distinct types for Microgrid ID and Dispatch ID though. Signed-off-by: Mathias L. Baumann --- RELEASE_NOTES.md | 1 + src/frequenz/client/dispatch/_client.py | 1 + tests/test_dispatch_client.py | 2 +- 3 files changed, 3 insertions(+), 1 deletion(-) diff --git a/RELEASE_NOTES.md b/RELEASE_NOTES.md index d16a3351..bc7c14c6 100644 --- a/RELEASE_NOTES.md +++ b/RELEASE_NOTES.md @@ -7,6 +7,7 @@ ## Upgrading - The `Dispatch` class is now a frozen dataclass, meaning that it is immutable. Modifications can still be done using `replace`: `dispatch = replace(dispatch, start_time=new_start_time)`. +- The `Client.update()` method now requires named parameters. ## New Features diff --git a/src/frequenz/client/dispatch/_client.py b/src/frequenz/client/dispatch/_client.py index 18d8cef1..6758a5a6 100644 --- a/src/frequenz/client/dispatch/_client.py +++ b/src/frequenz/client/dispatch/_client.py @@ -166,6 +166,7 @@ async def create( async def update( self, + *, dispatch_id: int, new_fields: dict[str, Any], ) -> None: diff --git a/tests/test_dispatch_client.py b/tests/test_dispatch_client.py index 2b6e6849..845b0325 100644 --- a/tests/test_dispatch_client.py +++ b/tests/test_dispatch_client.py @@ -99,7 +99,7 @@ async def test_update_dispatch() -> None: sample = _update(sample, dispatch) assert dispatch == sample - await client.update(dispatch.id, {"recurrence.interval": 4}) + await client.update(dispatch_id=dispatch.id, new_fields={"recurrence.interval": 4}) assert client.dispatches[0].recurrence.interval == 4