mirror of
https://github.com/BerriAI/litellm.git
synced 2026-09-12 23:01:41 +00:00
fix(langfuse): guard against None standard_callback_dynamic_params
_dynamic_langfuse_credentials_are_passed() now returns False immediately when standard_callback_dynamic_params is None, preventing the AttributeError that caused all Langfuse success callbacks to silently fail when credentials were supplied via environment variables. Closes #25940
This commit is contained in:
parent
f69b9d6564
commit
ef66b94455
2 changed files with 43 additions and 3 deletions
|
|
@ -86,9 +86,7 @@ class LangFuseHandler:
|
|||
if globalLangfuseLogger is not None:
|
||||
return globalLangfuseLogger
|
||||
|
||||
credentials_dict: Dict[
|
||||
str, Any
|
||||
] = (
|
||||
credentials_dict: Dict[str, Any] = (
|
||||
{}
|
||||
) # the global langfuse logger uses Environment Variables, there are no dynamic credentials
|
||||
globalLangfuseLogger = in_memory_dynamic_logger_cache.get_cache(
|
||||
|
|
@ -160,6 +158,9 @@ class LangFuseHandler:
|
|||
bool: True if the dynamic langfuse credentials are passed, False otherwise
|
||||
"""
|
||||
|
||||
if standard_callback_dynamic_params is None:
|
||||
return False
|
||||
|
||||
if (
|
||||
standard_callback_dynamic_params.get("langfuse_host") is not None
|
||||
or standard_callback_dynamic_params.get("langfuse_public_key") is not None
|
||||
|
|
|
|||
|
|
@ -0,0 +1,39 @@
|
|||
from litellm.integrations.langfuse.langfuse_handler import LangFuseHandler
|
||||
|
||||
|
||||
class TestLangFuseHandlerDynamicCredentials:
|
||||
def test_dynamic_credentials_none_returns_false(self):
|
||||
"""_dynamic_langfuse_credentials_are_passed should return False when
|
||||
standard_callback_dynamic_params is None (env-var-only config)."""
|
||||
result = LangFuseHandler._dynamic_langfuse_credentials_are_passed(None)
|
||||
assert result is False
|
||||
|
||||
def test_dynamic_credentials_empty_dict_returns_false(self):
|
||||
"""_dynamic_langfuse_credentials_are_passed should return False when
|
||||
standard_callback_dynamic_params is an empty dict."""
|
||||
result = LangFuseHandler._dynamic_langfuse_credentials_are_passed({})
|
||||
assert result is False
|
||||
|
||||
def test_dynamic_credentials_with_langfuse_host_returns_true(self):
|
||||
result = LangFuseHandler._dynamic_langfuse_credentials_are_passed(
|
||||
{"langfuse_host": "http://localhost:3000"}
|
||||
)
|
||||
assert result is True
|
||||
|
||||
def test_dynamic_credentials_with_public_key_returns_true(self):
|
||||
result = LangFuseHandler._dynamic_langfuse_credentials_are_passed(
|
||||
{"langfuse_public_key": "pk-lf-test"}
|
||||
)
|
||||
assert result is True
|
||||
|
||||
def test_dynamic_credentials_with_secret_key_returns_true(self):
|
||||
result = LangFuseHandler._dynamic_langfuse_credentials_are_passed(
|
||||
{"langfuse_secret_key": "sk-lf-test"}
|
||||
)
|
||||
assert result is True
|
||||
|
||||
def test_dynamic_credentials_with_secret_returns_true(self):
|
||||
result = LangFuseHandler._dynamic_langfuse_credentials_are_passed(
|
||||
{"langfuse_secret": "sk-lf-test"}
|
||||
)
|
||||
assert result is True
|
||||
Loading…
Add table
Reference in a new issue