Spaces:
Paused
Paused
Mirrowel
commited on
Commit
Β·
8d69bcd
1
Parent(s):
4d4a198
fix(client): π prevent provider initialization without configured credentials
Browse filesThe `_get_provider_instance` method now checks if credentials exist for a provider before attempting initialization. This prevents potential errors from initializing providers that lack proper configuration.
- Added credential existence check at the start of the method
- Returns `None` early if provider credentials are not configured
- Added debug logging to indicate when provider initialization is skipped
- Enhanced docstring with detailed Args and Returns documentation
This change improves system robustness by failing gracefully when providers are referenced but not properly configured.
src/rotator_library/client.py
CHANGED
|
@@ -393,7 +393,23 @@ class RotatingClient:
|
|
| 393 |
return os.getenv(api_base_env) is not None
|
| 394 |
|
| 395 |
def _get_provider_instance(self, provider_name: str):
|
| 396 |
-
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 397 |
if provider_name not in self._provider_instances:
|
| 398 |
if provider_name in self._provider_plugins:
|
| 399 |
self._provider_instances[provider_name] = self._provider_plugins[
|
|
|
|
| 393 |
return os.getenv(api_base_env) is not None
|
| 394 |
|
| 395 |
def _get_provider_instance(self, provider_name: str):
|
| 396 |
+
"""
|
| 397 |
+
Lazily initializes and returns a provider instance.
|
| 398 |
+
Only initializes providers that have configured credentials.
|
| 399 |
+
|
| 400 |
+
Args:
|
| 401 |
+
provider_name: The name of the provider to get an instance for.
|
| 402 |
+
|
| 403 |
+
Returns:
|
| 404 |
+
Provider instance if credentials exist, None otherwise.
|
| 405 |
+
"""
|
| 406 |
+
# Only initialize providers for which we have credentials
|
| 407 |
+
if provider_name not in self.all_credentials:
|
| 408 |
+
lib_logger.debug(
|
| 409 |
+
f"Skipping provider '{provider_name}' initialization: no credentials configured"
|
| 410 |
+
)
|
| 411 |
+
return None
|
| 412 |
+
|
| 413 |
if provider_name not in self._provider_instances:
|
| 414 |
if provider_name in self._provider_plugins:
|
| 415 |
self._provider_instances[provider_name] = self._provider_plugins[
|