Repository navigation
fix(proxy): skip database-dependent proxy hooks when no prisma client is configured - #36270
devin-ai-integration[bot] wants to merge 1 commit into
Conversation
… is configured 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 SummaryThe PR prevents database-dependent proxy hooks from being initialized without a Prisma client, avoiding post-provider failures in database-less deployments.
Confidence Score: 5/5The PR appears safe to merge, with database-less and database-backed hook initialization both handled consistently. The affected managed-resource hooks require Prisma for their operations, while existing consumers either fall back to provider-native behavior or return an explicit database-support error when those hooks are absent.
|
| Filename | Overview |
|---|---|
| litellm/proxy/utils.py | Adds an early skip for the two database-dependent managed-resource hooks when Prisma is unavailable; their consumers already support absence. |
| tests/test_litellm/proxy/utils/proxy_logging/test_lifecycle.py | Adds focused tests proving database-dependent hooks are omitted without Prisma and registered with the configured client otherwise. |
Reviews (1): Last reviewed commit: "fix(proxy): skip database-dependent prox..." | Re-trigger Greptile
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
TLDR
Problem this solves:
How it solves it:
User Flow
Before: a developer running the gateway without a database creates a batch, pays for it, and gets an error back with no id
"endpoint": "/v1/chat/completions"and"completion_window": "24h"500with{"error":{"message":"'NoneType' object has no attribute 'db'"}}, no batch id anywhereAfter: the same request returns the batch and the job is pollable
200with the batch object,"status": "validating", and a batch id"status": "completed"Relevant issues
Fixes #36265
Linear ticket
Pre-Submission checklist
Screenshots / Proof of Fix
A stub upstream on 127.0.0.1:8111 stands in for the provider batch API so the create is accepted and the job "starts" before the hook runs, which is the condition the bug needs. Config is one
openai/gpt-4odeployment pointed at that stub.Before, at c28cbb8 (no
DATABASE_URLin the environment):The upstream had already taken the job before that 500, so the money was spent:
Proxy log for the same request:
After, at ba02189, same DB-less boot and same curl:
DB-backed behavior unchanged, at ba02189 with
DATABASE_URLset, same curl returns 200 and the managed row still lands:Type
🐛 Bug Fix
Changes
_add_proxy_hooksnow skips any hook whose constructor asks forprisma_clientwhen the proxy has none, instead of handing itNoneand registering it anyway. The alternative, guarding inside the hook, would leave it half running: it would still rewrite ids and run access checks against a database it does not have, so the whole layer is better left off.Consumers already treat the hook as optional, either checking
is not Noneor raising a clear "Managed files hook not found" error on the managed-id paths that genuinely need a database, so a DB-less proxy simply has no managed files layer.Tests extend the existing
_add_proxy_hookscoverage intests/test_litellm/proxy/utils/proxy_logging/test_lifecycle.py: a hook requiringprisma_clientis left out of bothproxy_hook_mappingand the registered callbacks when there is no client, and is registered with the client when there is one. The first test fails on the current code.Link to Devin session: https://app.devin.ai/sessions/37ea5bad94be4095af288ee0e805dc35