mirror of
https://github.com/BerriAI/litellm.git
synced 2026-11-22 10:40:46 +00:00
Merge 4b51e5caca into e04e89c701
This commit is contained in:
commit
77bc0c7b3b
2 changed files with 29 additions and 3 deletions
|
|
@ -11,8 +11,6 @@ from datetime import datetime
|
|||
from functools import reduce
|
||||
from typing import TYPE_CHECKING, Any, Final, Literal, TypeAlias, TypeVar, cast
|
||||
|
||||
from redis.exceptions import RedisError
|
||||
|
||||
from litellm._internal_context import with_service_target
|
||||
from litellm._logging import verbose_proxy_logger
|
||||
from litellm.caching import RedisCache
|
||||
|
|
@ -520,6 +518,8 @@ class RedisUpdateBuffer:
|
|||
if self.redis_cache is None:
|
||||
return
|
||||
|
||||
from redis.exceptions import RedisError
|
||||
|
||||
restore_configs: Final = (
|
||||
(db_spend_update_transactions, REDIS_UPDATE_BUFFER_KEY),
|
||||
(daily_spend_update_transactions, REDIS_DAILY_SPEND_UPDATE_BUFFER_KEY),
|
||||
|
|
|
|||
|
|
@ -1,11 +1,13 @@
|
|||
import builtins
|
||||
import importlib.util
|
||||
import json
|
||||
from datetime import datetime, timezone
|
||||
from pathlib import Path
|
||||
from typing import Final
|
||||
from unittest.mock import AsyncMock, MagicMock, patch
|
||||
|
||||
import pytest
|
||||
|
||||
|
||||
from litellm.constants import REDIS_DAILY_TAG_SPEND_UPDATE_BUFFER_KEY
|
||||
from litellm.litellm_core_utils.safe_json_dumps import safe_dumps
|
||||
from litellm.proxy._types import DailyTagSpendTransaction
|
||||
|
|
@ -14,6 +16,30 @@ from litellm.proxy.db.db_transaction_queue.redis_update_buffer import RedisUpdat
|
|||
from litellm.proxy.proxy_server import ProxyStartupEvent
|
||||
|
||||
|
||||
def test_importing_module_does_not_require_redis(monkeypatch: pytest.MonkeyPatch) -> None:
|
||||
original_import: Final = builtins.__import__
|
||||
|
||||
def import_without_redis(
|
||||
name: str,
|
||||
globals: dict[str, object] | None = None,
|
||||
locals: dict[str, object] | None = None,
|
||||
fromlist: tuple[str, ...] = (),
|
||||
level: int = 0,
|
||||
) -> object:
|
||||
if name == "redis" or name.startswith("redis."):
|
||||
raise ModuleNotFoundError("No module named 'redis'")
|
||||
return original_import(name, globals, locals, fromlist, level)
|
||||
|
||||
monkeypatch.setattr(builtins, "__import__", import_without_redis)
|
||||
module_path: Final = Path(__file__).parents[5] / "litellm/proxy/db/db_transaction_queue/redis_update_buffer.py"
|
||||
spec: Final = importlib.util.spec_from_file_location("redis_update_buffer_without_redis", module_path)
|
||||
assert spec is not None
|
||||
assert spec.loader is not None
|
||||
|
||||
module: Final = importlib.util.module_from_spec(spec)
|
||||
spec.loader.exec_module(module)
|
||||
|
||||
|
||||
def _daily_tag_spend_update_transactions() -> dict[str, DailyTagSpendTransaction]:
|
||||
return {
|
||||
"research_2025-01-15_api-key-123_gpt-4o_openai_/chat/completions": DailyTagSpendTransaction(
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue