Skip to content

Commit 9c3e7b1

Browse files
committed
Do Pydantic workaround
1 parent ea8e085 commit 9c3e7b1

File tree

2 files changed

+12
-12
lines changed

2 files changed

+12
-12
lines changed

src/apify/_actor.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -128,10 +128,6 @@ def __init__(
128128
self._configure_logging = configure_logging
129129
self._apify_client = self.new_client()
130130

131-
# Create an instance of the cloud storage client, the local storage client is obtained
132-
# from the service locator.
133-
self._cloud_storage_client = ApifyStorageClient()
134-
135131
# Set the event manager based on whether the Actor is running on the platform or locally.
136132
self._event_manager = (
137133
ApifyEventManager(
@@ -282,6 +278,10 @@ async def init(self) -> None:
282278
if _ActorType._is_any_instance_initialized:
283279
self.log.warning('Repeated Actor initialization detected - this is non-standard usage, proceed with care')
284280

281+
# Create an instance of the cloud storage client, the local storage client is obtained
282+
# from the service locator
283+
self._cloud_storage_client = ApifyStorageClient(configuration=self.configuration)
284+
285285
# Make sure that the currently initialized instance is also available through the global `Actor` proxy
286286
cast('Proxy', Actor).__wrapped__ = self
287287

src/apify/_configuration.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -445,17 +445,17 @@ def get_configuration(self) -> Configuration:
445445
return self._configuration
446446

447447
stored_configuration = super().get_configuration()
448+
apify_configuration = Configuration()
448449

449450
# Ensure the returned configuration is of type Apify Configuration.
450451
# Most likely crawlee configuration was already set. Create Apify configuration from it.
451-
# Env vars will have lower priority than the stored configuration.
452-
model_dump = stored_configuration.model_dump()
453-
# The configuration will read env variables first and overridden with stored_configuration
454-
_config = Configuration()
455-
for key in model_dump:
456-
if model_dump[key]:
457-
setattr(_config, key, model_dump[key])
458-
return _config
452+
# Due to known Pydantic issue https://github.com/pydantic/pydantic/issues/9516, creating new instance of
453+
# Configuration from existing one in situation where environment can have some fields set by alias is very
454+
# unpredictable. Use the stable workaround.
455+
for name in stored_configuration.model_fields:
456+
setattr(apify_configuration, name, getattr(stored_configuration, name))
457+
458+
return apify_configuration
459459

460460

461461
# Ensure that ApifyServiceLocator is used to make sure Apify Configuration is used.

0 commit comments

Comments
 (0)