diff --git a/src/apify/_configuration.py b/src/apify/_configuration.py index 005b8e28..b88f9ae5 100644 --- a/src/apify/_configuration.py +++ b/src/apify/_configuration.py @@ -295,7 +295,7 @@ class Configuration(CrawleeConfiguration): alias='actor_max_paid_dataset_items', description='For paid-per-result Actors, the user-set limit on returned results. Do not exceed this limit', ), - BeforeValidator(lambda val: val or None), + BeforeValidator(lambda val: val if val != '' else None), ] = None max_total_charge_usd: Annotated[ @@ -304,7 +304,7 @@ class Configuration(CrawleeConfiguration): alias='actor_max_total_charge_usd', description='For pay-per-event Actors, the user-set limit on total charges. Do not exceed this limit', ), - BeforeValidator(lambda val: val or None), + BeforeValidator(lambda val: val if val != '' else None), ] = None test_pay_per_event: Annotated[ diff --git a/tests/unit/actor/test_configuration.py b/tests/unit/actor/test_configuration.py index 5199a07b..1448ecca 100644 --- a/tests/unit/actor/test_configuration.py +++ b/tests/unit/actor/test_configuration.py @@ -1,4 +1,5 @@ import json +from decimal import Decimal from pathlib import Path import pytest @@ -275,6 +276,34 @@ def test_default_values() -> None: assert config.test_pay_per_event is False +def test_max_paid_dataset_items_zero_is_preserved(monkeypatch: pytest.MonkeyPatch) -> None: + """Test that max_paid_dataset_items=0 is not treated as falsy and converted to None.""" + monkeypatch.setenv('ACTOR_MAX_PAID_DATASET_ITEMS', '0') + config = ApifyConfiguration() + assert config.max_paid_dataset_items == 0 + + +def test_max_total_charge_usd_zero_is_preserved(monkeypatch: pytest.MonkeyPatch) -> None: + """Test that max_total_charge_usd=0 is not treated as falsy and converted to None.""" + monkeypatch.setenv('ACTOR_MAX_TOTAL_CHARGE_USD', '0') + config = ApifyConfiguration() + assert config.max_total_charge_usd == Decimal(0) + + +def test_max_paid_dataset_items_empty_string_becomes_none(monkeypatch: pytest.MonkeyPatch) -> None: + """Test that an empty env var for max_paid_dataset_items is converted to None.""" + monkeypatch.setenv('ACTOR_MAX_PAID_DATASET_ITEMS', '') + config = ApifyConfiguration() + assert config.max_paid_dataset_items is None + + +def test_max_total_charge_usd_empty_string_becomes_none(monkeypatch: pytest.MonkeyPatch) -> None: + """Test that an empty env var for max_total_charge_usd is converted to None.""" + monkeypatch.setenv('ACTOR_MAX_TOTAL_CHARGE_USD', '') + config = ApifyConfiguration() + assert config.max_total_charge_usd is None + + def test_max_total_charge_usd_decimal_parsing(monkeypatch: pytest.MonkeyPatch) -> None: """Test that max_total_charge_usd is parsed as Decimal from env var.""" from decimal import Decimal