Commit 701185e
authored
fix: raise NotFoundError on ambiguous 404 responses (#755)
Follow-up to
#737 (comment)
`.get()` previously collapsed every 404 into `None` via
`catch_not_found_or_throw`. That works for direct, ID-identified fetches
(`client.dataset(id).get()`), where a 404 unambiguously means the named
resource is missing. It's misleading whenever a 404 is ambiguous — the
client can't tell which resource in the path is actually gone, and
silently returning `None` hides the cause.
This PR identifies three categories where a 404 is ambiguous and
propagates `NotFoundError` instead:
1. **Chained calls without an ID** (`run.dataset()`,
`run.key_value_store()`, `run.request_queue()`, `run.log()`) — a 404
could mean either the parent run is missing or the default sub-resource.
Covered by the base `_get` / `_delete` via a `resource_id is None →
raise` guard, so `.delete()` on a chained client also raises now; direct
`dataset(id).delete()` keeps its idempotent-DELETE semantics.
2. **Chained `LogClient`** — `run.log().get()` / `.get_as_bytes()` /
`.stream()` raise; direct `client.log(id).get()` still returns `None`.
3. **Singleton sub-path endpoints** — `ScheduleClient.get_log`,
`TaskClient.get_input`, `DatasetClient.get_statistics`,
`UserClient.monthly_usage`, `UserClient.limits`, `WebhookClient.test`.
These hit a fixed path (`/.../{id}/log`, `/.../{id}/input`, etc.) where
a 404 effectively always means the parent is missing. Return types moved
from `T | None` to `T`.
Record-by-key lookups (`KeyValueStoreClient.get_record(key)`,
`RequestQueueClient.get_request(request_id)`) keep the existing "None on
missing" behavior — the 404 is specifically about the record/request,
which is the natural meaning.
A shared helper `catch_not_found_for_resource_or_throw(exc,
resource_id)` in `_utils.py` centralizes the `resource_id is None →
raise` pattern across all 10 call sites. The v3 upgrade guide documents
the new semantics. Sync/async tests cover every code path, including
`client.actor('id').last_run().dataset().get()` (happy path +
ambiguous-404 case).1 parent 0995ca0 commit 701185e
10 files changed
Lines changed: 414 additions & 212 deletions
File tree
- docs/04_upgrading
- src/apify_client
- _resource_clients
- tests/unit
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
218 | 218 | | |
219 | 219 | | |
220 | 220 | | |
221 | | - | |
| 221 | + | |
222 | 222 | | |
223 | | - | |
| 223 | + | |
224 | 224 | | |
225 | | - | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
226 | 251 | | |
227 | 252 | | |
228 | 253 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
13 | | - | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
14 | 20 | | |
15 | 21 | | |
16 | 22 | | |
| |||
194 | 200 | | |
195 | 201 | | |
196 | 202 | | |
197 | | - | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
198 | 208 | | |
199 | 209 | | |
200 | 210 | | |
| |||
204 | 214 | | |
205 | 215 | | |
206 | 216 | | |
207 | | - | |
| 217 | + | |
208 | 218 | | |
209 | 219 | | |
210 | 220 | | |
| |||
219 | 229 | | |
220 | 230 | | |
221 | 231 | | |
222 | | - | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
223 | 237 | | |
224 | 238 | | |
225 | 239 | | |
| |||
228 | 242 | | |
229 | 243 | | |
230 | 244 | | |
231 | | - | |
| 245 | + | |
232 | 246 | | |
233 | 247 | | |
234 | 248 | | |
| |||
374 | 388 | | |
375 | 389 | | |
376 | 390 | | |
377 | | - | |
| 391 | + | |
| 392 | + | |
| 393 | + | |
| 394 | + | |
| 395 | + | |
378 | 396 | | |
379 | 397 | | |
380 | 398 | | |
| |||
384 | 402 | | |
385 | 403 | | |
386 | 404 | | |
387 | | - | |
| 405 | + | |
388 | 406 | | |
389 | 407 | | |
390 | 408 | | |
| |||
399 | 417 | | |
400 | 418 | | |
401 | 419 | | |
402 | | - | |
| 420 | + | |
| 421 | + | |
| 422 | + | |
| 423 | + | |
| 424 | + | |
403 | 425 | | |
404 | 426 | | |
405 | 427 | | |
| |||
408 | 430 | | |
409 | 431 | | |
410 | 432 | | |
411 | | - | |
| 433 | + | |
412 | 434 | | |
413 | 435 | | |
414 | 436 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
13 | | - | |
14 | 13 | | |
15 | 14 | | |
16 | 15 | | |
17 | 16 | | |
18 | | - | |
19 | 17 | | |
20 | 18 | | |
21 | 19 | | |
| |||
628 | 626 | | |
629 | 627 | | |
630 | 628 | | |
631 | | - | |
| 629 | + | |
632 | 630 | | |
633 | 631 | | |
634 | 632 | | |
| |||
637 | 635 | | |
638 | 636 | | |
639 | 637 | | |
640 | | - | |
641 | | - | |
642 | | - | |
643 | | - | |
644 | | - | |
645 | | - | |
646 | | - | |
647 | | - | |
648 | | - | |
649 | | - | |
650 | | - | |
651 | | - | |
652 | | - | |
| 638 | + | |
653 | 639 | | |
654 | | - | |
| 640 | + | |
| 641 | + | |
| 642 | + | |
| 643 | + | |
| 644 | + | |
| 645 | + | |
| 646 | + | |
| 647 | + | |
| 648 | + | |
| 649 | + | |
| 650 | + | |
655 | 651 | | |
656 | 652 | | |
657 | 653 | | |
| |||
1208 | 1204 | | |
1209 | 1205 | | |
1210 | 1206 | | |
1211 | | - | |
| 1207 | + | |
1212 | 1208 | | |
1213 | 1209 | | |
1214 | 1210 | | |
| |||
1217 | 1213 | | |
1218 | 1214 | | |
1219 | 1215 | | |
1220 | | - | |
1221 | | - | |
1222 | | - | |
1223 | | - | |
1224 | | - | |
1225 | | - | |
1226 | | - | |
1227 | | - | |
1228 | | - | |
1229 | | - | |
1230 | | - | |
1231 | | - | |
1232 | | - | |
| 1216 | + | |
1233 | 1217 | | |
1234 | | - | |
| 1218 | + | |
| 1219 | + | |
| 1220 | + | |
| 1221 | + | |
| 1222 | + | |
| 1223 | + | |
| 1224 | + | |
| 1225 | + | |
| 1226 | + | |
| 1227 | + | |
| 1228 | + | |
1235 | 1229 | | |
1236 | 1230 | | |
1237 | 1231 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
8 | | - | |
| 8 | + | |
9 | 9 | | |
10 | 10 | | |
11 | 11 | | |
| |||
39 | 39 | | |
40 | 40 | | |
41 | 41 | | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
42 | 45 | | |
43 | 46 | | |
44 | 47 | | |
| |||
57 | 60 | | |
58 | 61 | | |
59 | 62 | | |
60 | | - | |
| 63 | + | |
61 | 64 | | |
62 | 65 | | |
63 | 66 | | |
| |||
84 | 87 | | |
85 | 88 | | |
86 | 89 | | |
87 | | - | |
| 90 | + | |
88 | 91 | | |
89 | 92 | | |
90 | 93 | | |
| |||
113 | 116 | | |
114 | 117 | | |
115 | 118 | | |
116 | | - | |
| 119 | + | |
117 | 120 | | |
118 | 121 | | |
119 | 122 | | |
| |||
144 | 147 | | |
145 | 148 | | |
146 | 149 | | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
147 | 153 | | |
148 | 154 | | |
149 | 155 | | |
| |||
162 | 168 | | |
163 | 169 | | |
164 | 170 | | |
165 | | - | |
| 171 | + | |
166 | 172 | | |
167 | 173 | | |
168 | 174 | | |
| |||
189 | 195 | | |
190 | 196 | | |
191 | 197 | | |
192 | | - | |
| 198 | + | |
193 | 199 | | |
194 | 200 | | |
195 | 201 | | |
| |||
218 | 224 | | |
219 | 225 | | |
220 | 226 | | |
221 | | - | |
| 227 | + | |
222 | 228 | | |
223 | 229 | | |
224 | 230 | | |
| |||
0 commit comments