Skip to content

Commit fa58438

Browse files
authored
fix: Fix PlaywrightCrawler unintentionally setting the global configuration (#1747)
### Description - Remove unintentional side-effect: When a custom configuration was passed to the `PlaywrightCrawler`, it tried to set it in the global `service_locator` ### Testing - Updated unit test ### Checklist - [ ] CI passed
1 parent ea4fa01 commit fa58438

File tree

2 files changed

+7
-9
lines changed

2 files changed

+7
-9
lines changed

src/crawlee/crawlers/_playwright/_playwright_crawler.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
from pydantic import ValidationError
1313
from typing_extensions import NotRequired, TypedDict, TypeVar
1414

15-
from crawlee import service_locator
1615
from crawlee._request import Request, RequestOptions, RequestState
1716
from crawlee._types import BasicCrawlingContext, ConcurrencySettings
1817
from crawlee._utils.blocked import RETRY_CSS_SELECTORS
@@ -145,10 +144,6 @@ def __init__(
145144
not supported, use `navigation_timeout` instead.
146145
kwargs: Additional keyword arguments to pass to the underlying `BasicCrawler`.
147146
"""
148-
configuration = kwargs.pop('configuration', None)
149-
if configuration is not None:
150-
service_locator.set_configuration(configuration)
151-
152147
self._shared_navigation_timeouts: dict[int, SharedTimeout] = {}
153148

154149
if browser_pool:

tests/unit/crawlers/_playwright/test_playwright_crawler.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -791,12 +791,15 @@ async def request_handler(context: PlaywrightCrawlingContext) -> None:
791791
assert check_data['default'] != check_data['send_request']
792792

793793

794-
async def test_overwrite_configuration() -> None:
794+
async def test_passing_configuration() -> None:
795795
"""Check that the configuration is allowed to be passed to the Playwrightcrawler."""
796+
service_locator.set_configuration(Configuration(log_level='INFO'))
796797
configuration = Configuration(log_level='WARNING')
797-
PlaywrightCrawler(configuration=configuration)
798-
used_configuration = service_locator.get_configuration()
799-
assert used_configuration is configuration
798+
799+
crawler = PlaywrightCrawler(configuration=configuration)
800+
801+
assert service_locator.get_configuration().log_level == 'INFO'
802+
assert crawler._service_locator.get_configuration().log_level == 'WARNING'
800803

801804

802805
async def test_extract_links(server_url: URL) -> None:

0 commit comments

Comments
 (0)