Skip to content

Commit 8108ffd

Browse files
authored
Merge pull request #35 from Marenz/update_disallowed
Disallow updating `type` and `dry_run`
2 parents 2c2e30b + 2db0711 commit 8108ffd

File tree

3 files changed

+32
-6
lines changed

3 files changed

+32
-6
lines changed

RELEASE_NOTES.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
- 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)`.
1010
- The `Client.update()` method now requires named parameters.
11+
- `Client.update()` no longer accepts changes to the `type` and `dry_run` fields.
1112

1213
## New Features
1314

src/frequenz/client/dispatch/_client.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -177,9 +177,14 @@ async def update(
177177
178178
For recurrence fields, the keys are preceeded by "recurrence.".
179179
180+
Note that updating `type` and `dry_run` is not supported.
181+
180182
Args:
181183
dispatch_id: The dispatch_id to update.
182184
new_fields: The fields to update.
185+
186+
Raises:
187+
ValueError: If updating `type` or `dry_run`.
183188
"""
184189
msg = DispatchUpdateRequest(id=dispatch_id)
185190

@@ -188,7 +193,7 @@ async def update(
188193

189194
match path[0]:
190195
case "type":
191-
msg.update.type = val
196+
raise ValueError("Updating type is not supported")
192197
case "start_time":
193198
msg.update.start_time.FromDatetime(val)
194199
case "duration":
@@ -200,11 +205,8 @@ async def update(
200205
case "active":
201206
msg.update.is_active = val
202207
key = "is_active"
203-
case "is_dry_run":
204-
msg.update.is_dry_run = val
205-
case "dry_run":
206-
msg.update.is_dry_run = val
207-
key = "is_dry_run"
208+
case "is_dry_run" | "dry_run":
209+
raise ValueError("Updating dry_run is not supported")
208210
case "recurrence":
209211
match path[1]:
210212
case "freq":

tests/test_dispatch_client.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,29 @@ async def test_update_dispatch() -> None:
103103
assert client.dispatches[0].recurrence.interval == 4
104104

105105

106+
async def test_update_dispatch_fail() -> None:
107+
"""Test updating the type and dry_run fields of a dispatch."""
108+
sampler = DispatchGenerator()
109+
client = FakeClient()
110+
sample = sampler.generate_dispatch()
111+
112+
await client.create(**to_create_params(sample))
113+
dispatch = client.dispatches[0]
114+
115+
assert dispatch is not None
116+
117+
sample = _update(sample, dispatch)
118+
assert dispatch == sample
119+
120+
for field, value in [
121+
("type", "new_type"),
122+
("dry_run", True),
123+
("is_dry_run", True),
124+
]:
125+
with raises(ValueError):
126+
await client.update(dispatch_id=dispatch.id, new_fields={field: value})
127+
128+
106129
async def test_get_dispatch() -> None:
107130
"""Test getting a dispatch."""
108131
sampler = DispatchGenerator()

0 commit comments

Comments
 (0)