-
Notifications
You must be signed in to change notification settings - Fork 15
refactor!: Make Actor
initialization stricter and more predictable
#576
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 35 commits
8369ff9
d9137aa
cf1ee6f
d6b85ac
ea8e085
9c3e7b1
a2825bf
0b96454
432c79c
a4a046e
2a52cdc
841d89a
8bd59fd
c4b5d48
19ea5c7
54a3523
c89fd73
b4efbff
6a6ab98
f1ce0d1
8347eb6
b7101a4
19b79f1
b256876
6fbb5f4
5bf51f7
14c5395
f7c9a58
4450bf8
f28fcd7
c2c8ca5
7911c48
e68bdef
04e74bc
1cb295f
4b5946f
70890e7
2d61f1e
3813ea3
5608b4d
4b6c414
79b0ff7
b424c9b
cae107e
177dbb2
698c089
3b7634a
0de39ad
b19ea8c
85bf04d
47f84eb
7d1fc84
35ad0dd
28ebd8d
f884356
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
vdusek marked this conversation as resolved.
Show resolved
Hide resolved
vdusek marked this conversation as resolved.
Show resolved
Hide resolved
|
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,7 @@ | |
from pydantic import AliasChoices, BeforeValidator, Field, model_validator | ||
from typing_extensions import Self, deprecated | ||
|
||
from crawlee import service_locator | ||
from crawlee._utils.models import timedelta_ms | ||
from crawlee._utils.urls import validate_http_url | ||
from crawlee.configuration import Configuration as CrawleeConfiguration | ||
|
@@ -424,11 +425,35 @@ def disable_browser_sandbox_on_platform(self) -> Self: | |
def get_global_configuration(cls) -> Configuration: | ||
"""Retrieve the global instance of the configuration. | ||
|
||
Mostly for the backwards compatibility. It is recommended to use the `service_locator.get_configuration()` | ||
instead. | ||
This method ensures that ApifyConfigration is returned, even if CrawleeConfiguration was set in the | ||
service locator. | ||
""" | ||
return cls() | ||
global_configuration = service_locator.get_configuration() | ||
|
||
if isinstance(global_configuration, Configuration): | ||
# If Apify configuration was already stored in service locator, return it. | ||
return global_configuration | ||
|
||
# Monkey-patch the base class so that it works with the extended configuration | ||
CrawleeConfiguration.get_global_configuration = Configuration.get_global_configuration # type: ignore[method-assign] | ||
return cls.from_configuration(global_configuration) | ||
|
||
@classmethod | ||
def from_configuration(cls, configuration: CrawleeConfiguration) -> Configuration: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The result should be cached so that two calls to get_global_configuration always return the exact same object. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I added a warning to the only potential path where this could cause a problem. If someone gets there, it is not by intention, but for the sake of backward compatibility, it will still work in most cases as expected. |
||
"""Create Apify Configuration from existing Crawlee Configuration. | ||
|
||
Args: | ||
configuration: The existing Crawlee Configuration. | ||
|
||
Returns: | ||
The created Apify Configuration. | ||
""" | ||
apify_configuration = cls() | ||
|
||
# Ensure the returned configuration is of type Apify Configuration. | ||
# Most likely crawlee configuration was already set. Create Apify configuration from it. | ||
# Due to known Pydantic issue https://github.com/pydantic/pydantic/issues/9516, creating new instance of | ||
# Configuration from existing one in situation where environment can have some fields set by alias is very | ||
# unpredictable. Use the stable workaround. | ||
for name in configuration.model_fields: | ||
setattr(apify_configuration, name, getattr(configuration, name)) | ||
Pijukatel marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
return apify_configuration |
Uh oh!
There was an error while loading. Please reload this page.