Commit 237fc0c0 authored by Your Name's avatar Your Name

Fix provider initialization order - pass user config during __init__

parent dabdabc2
......@@ -112,9 +112,16 @@ def get_provider_handler(provider_id: str, api_key: Optional[str] = None, user_i
# Check if handler supports user_id parameter
import inspect
sig = inspect.signature(handler_class.__init__)
if 'user_id' in sig.parameters:
if 'user_id' in sig.parameters and 'provider_config' in sig.parameters:
logger.info(f"Creating handler with provider_id, api_key, user_id, and provider_config")
handler = handler_class(provider_id, api_key, user_id=user_id, provider_config=provider_config)
elif 'user_id' in sig.parameters:
logger.info(f"Creating handler with provider_id, api_key, and user_id")
handler = handler_class(provider_id, api_key, user_id=user_id)
# Set provider config to the user-specific config instead of loading from global config
if provider_config is not None:
handler.user_provider_config = provider_config
handler.provider_config = provider_config
else:
# For older providers that don't accept user_id parameter
logger.info(f"Creating handler with provider_id and api_key (no user_id support)")
......@@ -122,10 +129,8 @@ def get_provider_handler(provider_id: str, api_key: Optional[str] = None, user_i
handler = handler_class(provider_id, api_key)
# Set user_id manually for base class compatibility
handler.user_id = user_id
# Base class already handles default error tracking and rate limit for user providers
# Set provider config to the user-specific config instead of loading from global config
if user_id is not None and provider_config is not None:
if provider_config is not None:
handler.user_provider_config = provider_config
handler.provider_config = provider_config
......
......@@ -39,8 +39,13 @@ class KiloProviderHandler(BaseProviderHandler):
For non-admin users, credentials are loaded from the database.
"""
def __init__(self, provider_id: str, api_key: Optional[str] = None, user_id: Optional[int] = None):
def __init__(self, provider_id: str, api_key: Optional[str] = None, user_id: Optional[int] = None, provider_config: Optional[Any] = None):
super().__init__(provider_id, api_key, user_id=user_id)
if provider_config is not None:
# Use provider config passed from factory (user-specific config)
self.provider_config = provider_config
else:
# Fallback to global config
self.provider_config = config.get_provider(provider_id)
# Unified auth config with backward compatibility
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment