Skip to content

fix(proxy): point the startup schema drift check at the packaged schema.prisma - #52435

Merged
narmstrong-berri merged 1 commit into
mainfrom
nate_fix_schema_drift_check_path
Nov 20, 2026
Merged

narmstrong-berri merged 1 commit into
mainfrom
nate_fix_schema_drift_check_path

Conversation

@narmstrong-berri

@narmstrong-berri narmstrong-berri commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

Handwritten 1-3 sentence description

[insert handwritten description here]

Details

TLDR

Problem this solves:

  • With schema updates disabled, the drift check never reports drift
  • It reads ./schema.prisma, which moved under litellm/

How it solves it:

  • Diff against the schema.prisma shipped in litellm/proxy/
  • The path no longer depends on the working directory

User Flow

Before: an admin who disables schema updates is never told the database is behind the proxy's schema

  1. The admin starts the proxy with DISABLE_SCHEMA_UPDATE=true (or disable_prisma_schema_update: true) against a database missing tables
  2. The startup log shows Failed to generate migration diff ... Error trying to read Prisma schema file
  3. No prisma schema out of sync with db warning appears, so the drift goes unnoticed

After: the same boot reports the drift

  1. The admin starts the proxy the same way, from any directory
  2. The startup log lists the SQL needed to close the drift and logs prisma schema out of sync with db

Pre-Submission checklist

Please complete all items before asking a LiteLLM maintainer to review your PR

  • I have added meaningful tests
  • The handful of test files covering my change pass locally, e.g. uv run pytest tests/unit/<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
  • My PR passes all required CI/CD checks (e.g., lint, schema.d.ts sync check, etc.)
  • My PR's scope is as isolated as possible; it only solves 1 specific problem
  • Every automated review on my PR's latest commit has finished, and I have addressed or replied to each of its findings before requesting a maintainer review

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

E2E exception at 48f0319

Scope is the --to-schema-datamodel argument of prisma migrate diff in check_prisma_schema_diff_helper (litellm/proxy/db/check_migration.py). It was the relative ./schema.prisma, which only resolved when the proxy ran from a directory holding a copy, and the repo-root copy moved to litellm/schema.prisma in adc4c01 (#51006). It is now the absolute path of litellm/proxy/schema.prisma, resolved from the module, which ships in the wheel and in the Docker image and is kept identical to the other copies. Nothing else in the drift check changes, and the only caller is the boot path in proxy_cli.py when schema updates are disabled.

The bug was found by the Dec 1 integration contract tests (draft PR #50853). The test skipped with BUG for it is tests/integration/database/test_dec1_deploy_startup_database.py::test_with_schema_updates_disabled_an_empty_database_gets_no_tables (both the environment and config cells, in both groups).

The new regression test test_migrate_diff_reads_the_proxy_schema_from_any_working_directory runs the helper with run_prisma swapped for an in-process recorder, so no process starts, from a directory with no schema.prisma and checks the schema it was handed is an absolute path to a file declaring the LiteLLM models, with --script still last. It failed before the fix (the argument was the relative schema.prisma) and passes at the tip. The existing timeout test pinned the old ./schema.prisma argument, so it now checks the arguments before and after the path, --script included.

PYTHONPATH=. python -m pytest tests/unit/proxy/db/test_check_migration.py::test_migrate_diff_reads_the_proxy_schema_from_any_working_directory -q
# before the fix: 1 failed (assert False, PosixPath('schema.prisma').is_absolute())
# at the tip: 1 passed

PYTHONPATH=. python -m pytest tests/unit/proxy/db/test_check_migration.py -q
# at the tip: 5 passed

ruff format --check litellm/proxy/db/check_migration.py   # already formatted
ruff check litellm/proxy/db/check_migration.py   # all checks passed
ruff check --config .github/linters/ruff-tests.toml tests/unit/proxy/db/test_check_migration.py   # all checks passed

Type

Bug Fix

Final Attestation

  • The tests check the right things, including the edge cases, and regressions in the respective real-world customer use-cases are not possible after this PR

Generated by Claude Code

@veria-ai

veria-ai Bot commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

PR overview

No security issues were found in this pull request.

Reviews

Copy link
Copy Markdown
Contributor Author

[AI] @greptileai review


Generated by Claude Code

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔍 Devin Review: 1 flag

Not posted on this PR by your GitHub settings — view it in Devin Review. (Configure)

Devin Review

@greptile-apps

greptile-apps Bot commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 4/5

[Low impact] The change affects the proxy’s startup schema-drift diagnostic.

Satisfy the repository’s typing and in-process test requirements before merging.

Findings

  1. P2 New test lacks required types ▶
  2. P2 Unit test starts a subprocess ▶
  3. P2 SQL output loses test coverage ▶

Summary

The drift check now reads the packaged Prisma schema through an absolute path, so startup no longer depends on the working directory.

  • The startup drift check reads the proxy schema from any working directory.

Reviews (1) · Last reviewed commit: "fix(proxy): point the startup schema dri..." · Reviewed by Greptile

unrelated_dir.mkdir()
monkeypatch.chdir(unrelated_dir)

check_prisma_schema_diff_helper("postgresql://u:p@localhost:9/x")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Unit test starts a subprocess tests/unit/AGENTS.md bans subprocesses here. This test launches the fake CLI through run_prisma. Move it outside the unit suite.

Context Used: AGENTS.md (source)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[AI] Fixed in 48f0319. The new test no longer uses fake_prisma_cli. It swaps run_prisma for an in-process recorder and checks the argv it gets, so no process starts. The neighbouring timeout test still runs the fake CLI, as it does on main, since killing the process tree is what it tests. Moving that one is outside this PR.


Generated by Claude Code

Comment on lines +60 to +61
[call] = fake_prisma_cli.calls
assert call[:5] == ["migrate", "diff", "--from-url", "postgresql://u:p@localhost:9/x", "--to-schema-datamodel"]

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 SQL output loses test coverage The shortened assertion stops checking --script. Removing that flag would silently break SQL extraction. Keep asserting it alongside the path.

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[AI] Fixed in 48f0319. The timeout test asserts call[6:] == ["--script"] again next to the first five args, and the new path test checks --script is still last.


Generated by Claude Code

@codspeed

codspeed Bot commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

Merging this PR will not alter performance

1 warning

⚠️ 2 benchmarks are dominated by system calls

System calls cannot be simulated consistently and are left out of the measure. The reported value understates the real cost. Switch to the Walltime instrument to measure them.

Learn more about system calls

See affected benchmarks

✅ 45 untouched benchmarks


Comparing nate_fix_schema_drift_check_path (48f0319) with main (bb29e9a)1

Open in CodSpeed

Footnotes

  1. No successful run was found on main (36f23db) during the generation of this report, so bb29e9a was used instead as the comparison base. There might be some changes unrelated to this pull request in this report. ↩

@codecov

codecov Bot commented Nov 18, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@narmstrong-berri
narmstrong-berri force-pushed the nate_fix_schema_drift_check_path branch from 522c589 to f719cf9 Compare November 18, 2026 05:18
@narmstrong-berri narmstrong-berri self-assigned this Nov 18, 2026
@narmstrong-berri
narmstrong-berri force-pushed the nate_fix_schema_drift_check_path branch from f719cf9 to 48f0319 Compare November 18, 2026 21:06
@narmstrong-berri
narmstrong-berri merged commit 89c4d88 into main Nov 20, 2026
55 checks passed
@narmstrong-berri
narmstrong-berri deleted the nate_fix_schema_drift_check_path branch November 20, 2026 01:49
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.

2 participants