Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/apify/_configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -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[
Expand All @@ -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[
Expand Down
29 changes: 29 additions & 0 deletions tests/unit/actor/test_configuration.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import json
from decimal import Decimal
from pathlib import Path

import pytest
Expand Down Expand Up @@ -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
Expand Down