Repository navigation
fix(proxy-extras): tolerate unloadable psycopg - #50527
Closed
chamanswami555 wants to merge 4 commits into
Closed
chamanswami555 wants to merge 4 commits into
chamanswami555 wants to merge 4 commits into
Conversation
Author
|
hi, the workflows on this pr are waiting for a maintainer's approval (first contribution), so unit, lint and the title check have not run yet. could someone approve the runs when convenient? the cla is signed, and the fix has a job-level test plus a live before and after run in the description. thanks. |
Author
|
@mateo-berri @yucheng-berri sorry for the ping: this fixes the migration job crash on fips nodes from #49680 (psycopg cannot load libpq with PSYCOPG_IMPL=python). the workflows are waiting for approval, could one of you take a look when you have a minute? thanks. |
Contributor
7 of 8 tasks
Author
|
@ishaan-jaff @yassin-berriai could someone approve the workflow runs here? fips migration job crash from #49680, merges cleanly, veria found no issues |
Contributor
6 tasks done
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
<make-me-human-readable>the migration job died on nodes where the postgres driver cannot load, for example fips nodes that run the pure python driver on an image without libpq. with the default v2 resolver it died taking the migration lock, with the legacy resolver it died on the request-log index build. the lock now falls back to prisma's own advisory lock and the index build logs the skip, so the job finishes either way, the way the invalid index check already does when the driver is missing
</make-me-human-readable>Details
TLDR
problem this solves:
how it solves it:
psycopg_import_error, answers whether the driver loads and why notprisma migrate deployruns under prisma's own advisory lock, with the cause loggedUser Flow
before: on a fips node the migration job dies on the first
import psycopgit reachespython /app/litellm/proxy/prisma_migration.py, withPSYCOPG_IMPL=pythonset because the bundled libcrypto aborts on fipsprisma_migration_lockbefore any migration runs, with the legacy resolver the migrations apply and the job dies on the index buildImportError: couldn't import requested psycopg 'python' implementation: libpq library not found, the container exits non-zero and the rollout stallsafter: the same job finishes and reports what it skipped
psycopg could not be imported (... libpq library not found); running prisma migrate deploy under Prisma's own advisory lockand the migrations applypsycopg could not be imported (... libpq library not found); skipping the request-log index build until a run where it loads, thenSetup complete, and the job exits 0Relevant issues
fixes #49680
related: #50902 adds libpq to the shipped images, which makes psycopg load there. this one keeps the job alive on any image where it does not, and names the cause. #50511 (closed) guarded only the index build and returned false, so the job still exited 1 unless its env var was set
Affected release
regression in v1.105.0 for the index build (arrived in #43948, first tagged v1.105.0-rc.1) and in v1.107.0 for the deploy lock (arrived in #46368, first tagged v1.107.0-dev.2)
Pre-Submission checklist
Please complete all items before asking a LiteLLM maintainer to review your PR
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 moreDelays 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, run on a throwaway postgres 17 listening on 127.0.0.1:5499 with a fresh database per run. psycopg 3 is installed, as in the image, but libpq is kept off the library path (no
pg_configon PATH) andPSYCOPG_IMPL=pythonis set, soimport psycopgraisesImportError: couldn't import requested psycopg 'python' implementation: libpq library not found, the same error as the issue. the job is the one the image runs,python litellm/proxy/prisma_migration.py, andecho $?prints its exit code. full logs are 700 lines of migrations each, only the relevant lines are shown. before is the merge base, after is the branch tip, each resolver once. the branch was brought up to date with main on 12 nov, after the package move (#51000), so the paths below are the new onesBefore (52d1c4c), default v2 resolver
DATABASE_URL=postgresql://litellm@127.0.0.1:5499/litellm_e2e_v2_before_3 PSYCOPG_IMPL=python python litellm/proxy/prisma_migration.py; echo "exit code: $?"After (6a4c9c4), default v2 resolver
DATABASE_URL=postgresql://litellm@127.0.0.1:5499/litellm_e2e_v2_after_3 PSYCOPG_IMPL=python python litellm/proxy/prisma_migration.py; echo "exit code: $?"Before (52d1c4c), legacy resolver
DATABASE_URL=postgresql://litellm@127.0.0.1:5499/litellm_e2e_before_6 PSYCOPG_IMPL=python USE_V2_MIGRATION_RESOLVER=false python litellm/proxy/prisma_migration.py; echo "exit code: $?"After (6a4c9c4), legacy resolver
DATABASE_URL=postgresql://litellm@127.0.0.1:5499/litellm_e2e_after_6 PSYCOPG_IMPL=python USE_V2_MIGRATION_RESOLVER=false python litellm/proxy/prisma_migration.py; echo "exit code: $?"Type
🐛 Bug Fix
Caveats (if any)
Low
Database migration cannot proceedand the cause instead of a tracebackFinal Attestation