Repository navigation
fix(auth): cache team member default budget as a typed model (LIT-5311) - #37695
Conversation
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
|
|
Greptile SummaryThis PR fixes Redis-backed caching of team-member default budgets by validating database rows as
Confidence Score: 5/5The PR appears safe to merge, with the typed cache behavior aligned with existing cache serialization and authentication-budget patterns. The changed path validates the database row before caching, serializes it through the typed JSON codec, and reconstructs the same budget model on reads; no concrete blocking or non-blocking defect remains.
|
| Filename | Overview |
|---|---|
| litellm/proxy/auth/auth_checks.py | Uses the established typed-cache protocol for team-member default budgets, preventing raw datetime fields from reaching Redis serialization. |
| tests/test_litellm/proxy/auth/test_auth_checks.py | Adds focused regression coverage proving JSON-safe writes, typed reads, and reuse of the cached budget without another database lookup. |
Reviews (1): Last reviewed commit: "fix(auth): cache team member default bud..." | Re-trigger Greptile
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
tin-berri
left a comment
There was a problem hiding this comment.
Small, correct fix — caches the team-member default budget through UserApiKeyCache's typed model_type path instead of raw dict, so Redis gets a JSON-serializable payload instead of choking on the raw datetime columns (which silently dropped the cache write and forced every pod back to the DB on every request). Test correctly exercises the actual failure mode with a bare-json.dumps() stand-in for RedisCache rather than a permissive mock, and confirms the second call hits cache (find_unique awaited once). No auth/authz logic touched, purely a caching-layer serialization fix. CI green.
TLDR
Problem this solves:
How it solves it:
LiteLLM_BudgetTable, not the raw rowmodel_typeon both read and writeUser Flow
Before: a team admin with Redis-backed auth caching sees a recurring cache error, and every pod keeps hitting the database for the team's per-member budget
enable_redis_auth_cache: trueand a Redis cache backend"team_member_budget": 25, which comes back with a team idLiteLLM Redis Caching: async set() - Got exception from REDIS Object of type datetime is not JSON serializableAfter: the same flow is quiet, and the budget is shared across pods through Redis
Relevant issues
Linear ticket
Resolves LIT-5311
Pre-Submission checklist
Please complete all items before asking a LiteLLM maintainer to review your PR
uv run pytest tests/test_litellm/<your_test_file>.py -v. Leave the suites (make test-unit-*,make test-unit) to CI: it finishes in ~15 minutes where a laptop takes an hour or more@greptileaito re-request a review after pushing changes)Delays in PR merge?
If you're seeing a delay in your PR being merged, ping the LiteLLM Team on Slack (#pr-review).
Screenshots / Proof of Fix
Shared setup, identical on both sides: local Redis on 6379,
litellm/proxy/dev_config.yamlplusTeam and key created once against the same database, with a real Anthropic call:
Before (3a31331)
redis-cli keys 'team_member_default_budget*'After (b85546f)
grep -c "Object of type datetime is not JSON serializable" litellm.logredis-cli keys 'team_member_default_budget*' redis-cli get team_member_default_budget:team-lit5311-team-budget-0cfdc66ac73c44dd80df22ea170a65c0Type
🐛 Bug Fix
Caveats (if any)
Final Attestation
Link to Devin session: https://app.devin.ai/sessions/225c12d857dd4668b01f73235a1705c1
Requested by: @yassin-berriai