Skip to content

Commit a3d6958

Browse files
authored
chore(deps): Upgrade pydantic-settings to v2.12 (#1549)
### Description Upgrade `pydantic-settings` to v2.12. This release fixes the issue where environment variables were taking precedence over explicitly provided field values during model instantiation. ### Issues - Closes: #146
1 parent 6f78be4 commit a3d6958

16 files changed

+31
-63
lines changed

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ dependencies = [
3939
"more-itertools>=10.2.0",
4040
"protego>=0.5.0",
4141
"psutil>=6.0.0",
42-
"pydantic-settings>=2.2.0,!=2.7.0,!=2.7.1,!=2.8.0",
42+
"pydantic-settings>=2.12.0",
4343
"pydantic>=2.11.0",
4444
"pyee>=9.0.0",
4545
"tldextract>=5.1.0",

src/crawlee/configuration.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,9 @@ class Configuration(BaseSettings):
2828
Settings can also be configured via environment variables, prefixed with `CRAWLEE_`.
2929
"""
3030

31-
model_config = SettingsConfigDict(validate_by_name=True, validate_by_alias=True)
31+
# TODO: https://github.com/pydantic/pydantic-settings/issues/706
32+
# Use `SettingsConfigDict(validate_by_name=True, validate_by_alias=True)` when issue is resolved.
33+
model_config = SettingsConfigDict(populate_by_name=True)
3234

3335
internal_timeout: Annotated[timedelta | None, Field(alias='crawlee_internal_timeout')] = None
3436
"""Timeout for the internal asynchronous operations."""

tests/unit/conftest.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
# TODO: Update crawlee_storage_dir args once the Pydantic bug is fixed
2-
# https://github.com/apify/crawlee-python/issues/146
3-
41
from __future__ import annotations
52

63
import logging

tests/unit/crawlers/_basic/test_basic_crawler.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1102,7 +1102,7 @@ async def test_services_crawlers_can_use_different_services() -> None:
11021102

11031103
async def test_crawler_uses_default_storages(tmp_path: Path) -> None:
11041104
configuration = Configuration(
1105-
crawlee_storage_dir=str(tmp_path), # type: ignore[call-arg]
1105+
storage_dir=str(tmp_path),
11061106
purge_on_start=True,
11071107
)
11081108
service_locator.set_configuration(configuration)
@@ -1120,7 +1120,7 @@ async def test_crawler_uses_default_storages(tmp_path: Path) -> None:
11201120

11211121
async def test_crawler_can_use_other_storages(tmp_path: Path) -> None:
11221122
configuration = Configuration(
1123-
crawlee_storage_dir=str(tmp_path), # type: ignore[call-arg]
1123+
storage_dir=str(tmp_path),
11241124
purge_on_start=True,
11251125
)
11261126
service_locator.set_configuration(configuration)
@@ -1148,11 +1148,11 @@ async def test_crawler_can_use_other_storages_of_same_type(tmp_path: Path) -> No
11481148
}
11491149

11501150
configuration_a = Configuration(
1151-
crawlee_storage_dir=str(a_path), # type: ignore[call-arg]
1151+
storage_dir=str(a_path),
11521152
purge_on_start=True,
11531153
)
11541154
configuration_b = Configuration(
1155-
crawlee_storage_dir=str(b_path), # type: ignore[call-arg]
1155+
storage_dir=str(b_path),
11561156
purge_on_start=True,
11571157
)
11581158

@@ -1652,7 +1652,7 @@ async def _run_crawler(requests: list[str], storage_dir: str) -> StatisticsState
16521652
Must be defined like this to be pickable for ProcessPoolExecutor."""
16531653
service_locator.set_configuration(
16541654
Configuration(
1655-
crawlee_storage_dir=storage_dir, # type: ignore[call-arg]
1655+
storage_dir=storage_dir,
16561656
purge_on_start=False,
16571657
)
16581658
)

tests/unit/storage_clients/_file_system/test_fs_dataset_client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
@pytest.fixture
2121
def configuration(tmp_path: Path) -> Configuration:
2222
return Configuration(
23-
crawlee_storage_dir=str(tmp_path), # type: ignore[call-arg]
23+
storage_dir=str(tmp_path),
2424
)
2525

2626

tests/unit/storage_clients/_file_system/test_fs_kvs_client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
@pytest.fixture
2121
def configuration(tmp_path: Path) -> Configuration:
2222
return Configuration(
23-
crawlee_storage_dir=str(tmp_path), # type: ignore[call-arg]
23+
storage_dir=str(tmp_path),
2424
)
2525

2626

tests/unit/storage_clients/_file_system/test_fs_rq_client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
@pytest.fixture
2121
def configuration(tmp_path: Path) -> Configuration:
2222
return Configuration(
23-
crawlee_storage_dir=str(tmp_path), # type: ignore[call-arg]
23+
storage_dir=str(tmp_path),
2424
)
2525

2626

tests/unit/storage_clients/_sql/test_sql_dataset_client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
def configuration(tmp_path: Path) -> Configuration:
2626
"""Temporary configuration for tests."""
2727
return Configuration(
28-
crawlee_storage_dir=str(tmp_path), # type: ignore[call-arg]
28+
storage_dir=str(tmp_path),
2929
)
3030

3131

tests/unit/storage_clients/_sql/test_sql_kvs_client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
def configuration(tmp_path: Path) -> Configuration:
2828
"""Temporary configuration for tests."""
2929
return Configuration(
30-
crawlee_storage_dir=str(tmp_path), # type: ignore[call-arg]
30+
storage_dir=str(tmp_path),
3131
)
3232

3333

tests/unit/storage_clients/_sql/test_sql_rq_client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
def configuration(tmp_path: Path) -> Configuration:
2929
"""Temporary configuration for tests."""
3030
return Configuration(
31-
crawlee_storage_dir=str(tmp_path), # type: ignore[call-arg]
31+
storage_dir=str(tmp_path),
3232
)
3333

3434

0 commit comments

Comments
 (0)