Skip to content

Commit 8bcabe8

Browse files
committed
refactor: keep max_paid_dataset_items config field, remove only disable_outdated_warning and fact
1 parent 88d6242 commit 8bcabe8

5 files changed

Lines changed: 28 additions & 16 deletions

File tree

docs/02_concepts/code/11_conditional_actor_charge.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import asyncio
2-
import os
32

43
from apify import Actor
54

@@ -16,7 +15,7 @@ async def main() -> None:
1615
if Actor.get_charging_manager().get_pricing_info().is_pay_per_event:
1716
# highlight-end
1817
await Actor.push_data({'hello': 'world'}, charged_event_name='dataset-item')
19-
elif charged_items < int(os.environ.get('ACTOR_MAX_PAID_DATASET_ITEMS') or 0):
18+
elif charged_items < (Actor.configuration.max_paid_dataset_items or 0):
2019
await Actor.push_data({'hello': 'world'})
2120
charged_items += 1
2221

docs/04_upgrading/upgrading_to_v4.md

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -73,21 +73,9 @@ The deprecated `latest_sdk_version`, `log_format`, and `standby_port` fields hav
7373

7474
### Unused Configuration fields
7575

76-
The `disable_outdated_warning`, `fact`, and `max_paid_dataset_items` fields have been removed from `Configuration`. The SDK never read any of them, and `Actor.get_env()` no longer includes their keys. The corresponding `ActorEnvVars.MAX_PAID_DATASET_ITEMS`, `ApifyEnvVars.DISABLE_OUTDATED_WARNING`, and `ApifyEnvVars.FACT` enum entries remain available.
76+
The `disable_outdated_warning` and `fact` fields have been removed from `Configuration`. The SDK never read either of them, and `Actor.get_env()` no longer includes their keys. The corresponding `ApifyEnvVars.DISABLE_OUTDATED_WARNING` and `ApifyEnvVars.FACT` enum entries remain available.
7777

78-
- `disable_outdated_warning` and `fact` have no replacement. SDK version checking isn't supported for the Python SDK, so there is no outdated-version warning to disable.
79-
- `max_paid_dataset_items` only mirrored the `ACTOR_MAX_PAID_DATASET_ITEMS` environment variable — read the environment variable directly instead:
80-
81-
```python
82-
import os
83-
84-
# Before (v3)
85-
max_paid_dataset_items = Actor.configuration.max_paid_dataset_items
86-
87-
# After (v4)
88-
env_value = os.environ.get('ACTOR_MAX_PAID_DATASET_ITEMS')
89-
max_paid_dataset_items = int(env_value) if env_value else None
90-
```
78+
Neither has a replacement. SDK version checking isn't supported for the Python SDK, so there's no outdated-version warning to disable.
9179

9280
### wait_for_finish argument of Actor.start
9381

src/apify/_configuration.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,15 @@ class Configuration(CrawleeConfiguration):
300300
),
301301
] = False
302302

303+
max_paid_dataset_items: Annotated[
304+
int | None,
305+
Field(
306+
validation_alias='actor_max_paid_dataset_items',
307+
description='For paid-per-result Actors, the user-set limit on returned results. Do not exceed this limit',
308+
),
309+
BeforeValidator(_default_if_empty(default=None)),
310+
] = None
311+
303312
max_total_charge_usd: Annotated[
304313
Decimal | None,
305314
Field(

tests/unit/actor/test_actor_env_helpers.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
from apify._consts import ActorEnvVars, ApifyEnvVars
1313

1414
INTEGER_ENV_VARS: list[ActorEnvVars | ApifyEnvVars] = [
15+
ActorEnvVars.MAX_PAID_DATASET_ITEMS,
1516
ActorEnvVars.MEMORY_MBYTES,
1617
ActorEnvVars.STANDBY_PORT,
1718
ActorEnvVars.WEB_SERVER_PORT,

tests/unit/actor/test_configuration.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,13 +276,27 @@ def test_default_values() -> None:
276276
assert config.test_pay_per_event is False
277277

278278

279+
def test_max_paid_dataset_items_zero_is_preserved(monkeypatch: pytest.MonkeyPatch) -> None:
280+
"""Test that max_paid_dataset_items=0 is not treated as falsy and converted to None."""
281+
monkeypatch.setenv('ACTOR_MAX_PAID_DATASET_ITEMS', '0')
282+
config = ApifyConfiguration()
283+
assert config.max_paid_dataset_items == 0
284+
285+
279286
def test_max_total_charge_usd_zero_is_preserved(monkeypatch: pytest.MonkeyPatch) -> None:
280287
"""Test that max_total_charge_usd=0 is not treated as falsy and converted to None."""
281288
monkeypatch.setenv('ACTOR_MAX_TOTAL_CHARGE_USD', '0')
282289
config = ApifyConfiguration()
283290
assert config.max_total_charge_usd == Decimal(0)
284291

285292

293+
def test_max_paid_dataset_items_empty_string_becomes_none(monkeypatch: pytest.MonkeyPatch) -> None:
294+
"""Test that an empty env var for max_paid_dataset_items is converted to None."""
295+
monkeypatch.setenv('ACTOR_MAX_PAID_DATASET_ITEMS', '')
296+
config = ApifyConfiguration()
297+
assert config.max_paid_dataset_items is None
298+
299+
286300
def test_max_total_charge_usd_empty_string_becomes_none(monkeypatch: pytest.MonkeyPatch) -> None:
287301
"""Test that an empty env var for max_total_charge_usd is converted to None."""
288302
monkeypatch.setenv('ACTOR_MAX_TOTAL_CHARGE_USD', '')
@@ -384,6 +398,7 @@ def test_actor_storage_json_env_var(monkeypatch: pytest.MonkeyPatch) -> None:
384398
('env_var', 'attr', 'expected'),
385399
[
386400
('APIFY_TIMEOUT_AT', 'timeout_at', None),
401+
('ACTOR_MAX_PAID_DATASET_ITEMS', 'max_paid_dataset_items', None),
387402
('ACTOR_MAX_TOTAL_CHARGE_USD', 'max_total_charge_usd', None),
388403
('APIFY_USER_IS_PAYING', 'user_is_paying', False),
389404
],

0 commit comments

Comments
 (0)