Commit b609955
authored
refactor: consolidate empty-string env-var validators in Configuration (#965)
## Description
A few `Configuration` fields were already guarded against empty-string
env vars with ad-hoc `BeforeValidator` lambdas. The Apify platform
sometimes sets an env var to an empty string instead of leaving it unset
(see #303, or this [Discord
thread](https://discord.com/channels/801163717915574323/1020281045205123102/threads/1294774068528156817)),
and for these fields `''` cannot be parsed into the target type, so
without the guard validation would raise and crash `Actor.init()`.
This PR is a pure refactor: it consolidates those repeated lambdas into
a single shared `_default_if_empty(default=...)` validator. There is no
behavior change, and the empty-string handling is **not** extended to
any new fields.
### Changes
- Added a shared `_default_if_empty(default=...)` validator.
- Replaced the existing ad-hoc lambdas with it on the four fields that
already handled `''`:
- `max_paid_dataset_items` (→ `None`)
- `max_total_charge_usd` (→ `None`)
- `timeout_at` (→ `None`)
- `user_is_paying` (→ `False`)
- Added a parametrized regression test covering those four fields.1 parent b5f026f commit b609955
2 files changed
Lines changed: 40 additions & 5 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
8 | | - | |
| 8 | + | |
9 | 9 | | |
10 | 10 | | |
11 | 11 | | |
| |||
23 | 23 | | |
24 | 24 | | |
25 | 25 | | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
26 | 29 | | |
27 | 30 | | |
28 | 31 | | |
| |||
34 | 37 | | |
35 | 38 | | |
36 | 39 | | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
37 | 54 | | |
38 | 55 | | |
39 | 56 | | |
| |||
294 | 311 | | |
295 | 312 | | |
296 | 313 | | |
297 | | - | |
| 314 | + | |
298 | 315 | | |
299 | 316 | | |
300 | 317 | | |
| |||
303 | 320 | | |
304 | 321 | | |
305 | 322 | | |
306 | | - | |
| 323 | + | |
307 | 324 | | |
308 | 325 | | |
309 | 326 | | |
| |||
382 | 399 | | |
383 | 400 | | |
384 | 401 | | |
385 | | - | |
| 402 | + | |
386 | 403 | | |
387 | 404 | | |
388 | 405 | | |
| |||
416 | 433 | | |
417 | 434 | | |
418 | 435 | | |
419 | | - | |
| 436 | + | |
420 | 437 | | |
421 | 438 | | |
422 | 439 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
392 | 392 | | |
393 | 393 | | |
394 | 394 | | |
| 395 | + | |
| 396 | + | |
| 397 | + | |
| 398 | + | |
| 399 | + | |
| 400 | + | |
| 401 | + | |
| 402 | + | |
| 403 | + | |
| 404 | + | |
| 405 | + | |
| 406 | + | |
| 407 | + | |
| 408 | + | |
| 409 | + | |
| 410 | + | |
| 411 | + | |
| 412 | + | |
0 commit comments