Skip to content

fix(proxy): skip database-dependent proxy hooks when no prisma client is configured - #36270

Closed
devin-ai-integration[bot] wants to merge 1 commit into
litellm_internal_stagingfrom
devin_ai_dbless_proxy_hooks_36265
Closed

devin-ai-integration[bot] wants to merge 1 commit into
litellm_internal_stagingfrom
devin_ai_dbless_proxy_hooks_36265

Conversation

@devin-ai-integration

Copy link
Copy Markdown
Contributor

TLDR

Problem this solves:

  • DB-less proxy 500s on batch create after the provider already started the job
  • Caller never sees the batch id, so a paid job is orphaned
  • Same 500 hits fine-tuning job create on a DB-less proxy

How it solves it:

  • Skip registering proxy hooks whose constructor needs a prisma client when there is none
  • Today that is only the managed files hook, and every consumer already handles it being absent

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

  1. They send POST http://localhost:4000/v1/batches with an input file id, "endpoint": "/v1/chat/completions" and "completion_window": "24h"
  2. The provider accepts the job and starts running it, so the spend is already committed
  3. The response is 500 with {"error":{"message":"'NoneType' object has no attribute 'db'"}}, no batch id anywhere
  4. They cannot poll, cancel, or fetch output for that job, and retrying the create starts a second paid job

After: the same request returns the batch and the job is pollable

  1. They send the same POST http://localhost:4000/v1/batches
  2. The response is 200 with the batch object, "status": "validating", and a batch id
  3. They poll GET http://localhost:4000/v1/batches/{id} and watch it reach "status": "completed"
  4. With a database configured, nothing changes: the same create still returns 200 and the managed batch bookkeeping still happens

Relevant issues

Fixes #36265

Linear ticket

Pre-Submission checklist

  • I have added meaningful tests
  • My PR passes all CI/CD checks (e.g., lint, format, unit tests)
  • My PR's scope is as isolated as possible; it only solves 1 specific problem
  • I have received a Greptile Confidence Score of at least 4/5 before requesting a maintainer review

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-4o deployment pointed at that stub.

Before, at c28cbb8 (no DATABASE_URL in the environment):

$ curl -s -i -X POST http://127.0.0.1:4000/v1/batches -H 'Authorization: Bearer sk-1234' -H 'content-type: application/json' \
  -d '{"input_file_id":"file-stub","endpoint":"/v1/chat/completions","completion_window":"24h","model":"gpt-4o-batch"}'
HTTP/1.1 500 Internal Server Error
{"error":{"message":"'NoneType' object has no attribute 'db'","type":"internal_server_error","param":"None","code":"500"}}

The upstream had already taken the job before that 500, so the money was spent:

$ grep 'STUB got' stub.log
STUB got batch create: {"completion_window": "24h", "endpoint": "/v1/chat/completions", "input_file_id": "file-stub", "metadata": null}

Proxy log for the same request:

File "litellm/proxy/batches_endpoints/endpoints.py", line 314, in create_batch
  response = await proxy_logging_obj.post_call_success_hook(
File "enterprise/litellm_enterprise/proxy/hooks/managed_files.py", line 1278, in async_post_call_success_hook
  await self.store_unified_object_id(
File "enterprise/litellm_enterprise/proxy/hooks/managed_files.py", line 231, in store_unified_object_id
  await self.prisma_client.db.litellm_managedobjecttable.upsert(
AttributeError: 'NoneType' object has no attribute 'db'

After, at ba02189, same DB-less boot and same curl:

$ curl -s -i -X POST http://127.0.0.1:4000/v1/batches -H 'Authorization: Bearer sk-1234' -H 'content-type: application/json' \
  -d '{"input_file_id":"file-stub","endpoint":"/v1/chat/completions","completion_window":"24h","model":"gpt-4o-batch"}'
HTTP/1.1 200 OK
{"id":"batch_bGl0ZWxsbTpiYXRjaF9zdHViXzEyMzttb2RlbCxncHQtNG8tYmF0Y2g","completion_window":"24h","endpoint":"/v1/chat/completions","input_file_id":"file-bGl0ZWxsbTpmaWxlLXN0dWI7bW9kZWwsZ3B0LTRvLWJhdGNo","object":"batch","status":"validating", ...}

$ curl -s http://127.0.0.1:4000/v1/batches/batch_bGl0ZWxsbTpiYXRjaF9zdHViXzEyMzttb2RlbCxncHQtNG8tYmF0Y2g -H 'Authorization: Bearer sk-1234'
{"id":"batch_bGl0ZWxsbTpiYXRjaF9zdHViXzEyMzttb2RlbCxncHQtNG8tYmF0Y2g", ... "status":"completed", ...}

DB-backed behavior unchanged, at ba02189 with DATABASE_URL set, same curl returns 200 and the managed row still lands:

$ PGPASSWORD=... psql -h localhost -U postgres -d litellm -c 'select unified_object_id, file_purpose, status from "LiteLLM_ManagedObjectTable";'
                       unified_object_id                       | file_purpose |   status
---------------------------------------------------------------+--------------+------------
 batch_bGl0ZWxsbTpiYXRjaF9zdHViXzEyMzttb2RlbCxncHQtNG8tYmF0Y2g | batch        | validating
(1 row)

Type

🐛 Bug Fix

Changes

_add_proxy_hooks now skips any hook whose constructor asks for prisma_client when the proxy has none, instead of handing it None and 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 None or 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_hooks coverage in tests/test_litellm/proxy/utils/proxy_logging/test_lifecycle.py: a hook requiring prisma_client is left out of both proxy_hook_mapping and 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

… is configured

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@devin-ai-integration

Copy link
Copy Markdown
Contributor Author

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR. Add '(aside)' to your comment to have me ignore it.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment, CI, and merge conflict monitoring

@CLAassistant

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

@greptile-apps

greptile-apps Bot commented Aug 8, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

The PR prevents database-dependent proxy hooks from being initialized without a Prisma client, avoiding post-provider failures in database-less deployments.

  • Skips hook registration when the constructor requires prisma_client but no client is configured.
  • Preserves registration and callback behavior when a Prisma client is available.
  • Adds lifecycle tests covering both database-less and database-backed initialization.

Confidence Score: 5/5

The 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.

Important Files Changed

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

codecov Bot commented Aug 8, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@codspeed

codspeed Bot commented Aug 8, 2026

Copy link
Copy Markdown
Contributor

Merging this PR will not alter performance

✅ 31 untouched benchmarks


Comparing devin_ai_dbless_proxy_hooks_36265 (ba02189) with litellm_internal_staging (c28cbb8)

Open in CodSpeed

@yuneng-berri
yuneng-berri deleted the branch litellm_internal_staging September 13, 2026 04:40
@yuneng-berri yuneng-berri reopened this Sep 13, 2026
@github-actions

Copy link
Copy Markdown
Contributor

#36265 was fixed by #36273 on main, so this pull request is closed. Reopen it if something was missed.

@github-actions github-actions Bot closed this Sep 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: DB-less proxy 500s on batch create after the provider job already started, managed files hook dereferences prisma_client=None

2 participants