Repository navigation
fix(proxy-extras): decode text settings and catalog values read on SQL_ASCII databases - #52287
Closed
sukhdeepjohar wants to merge 1 commit into
Closed
sukhdeepjohar wants to merge 1 commit into
sukhdeepjohar wants to merge 1 commit into
Conversation
…L_ASCII databases On a SQL_ASCII database psycopg returns text values as bytes, so the request-log index build read SHOW block_size as "b'8192'" and crashed before building its indexes. Decode every text value find_blockers reads through one helper.
Contributor
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.
Handwritten 1-3 sentence description
[insert handwritten description here]
Details
TLDR
Problem this solves:
int("b'8192'")failsHow it solves it:
_text()helper decodes bytes before use inmigration_data_checks.pyUser Flow
Before: an admin whose Postgres database was created with encoding SQL_ASCII never gets the request-log indexes
DATABASE_URLpointing at that database, and the migrations applyException in thread litellm-request-log-indexesending inValueError: invalid literal for int() with base 10: "b'8192'"LiteLLM_SpendLogs_api_key_startTime_idx,LiteLLM_SpendLogs_litellm_call_id_idxandLiteLLM_DailyUserSpend_api_key_date_idxdo not existAfter: the same database gets all three indexes at startup
DATABASE_URLpointing at that database, and the migrations applyRelevant issues
Fixes #52247
Affected release
Regression in v1.109.0, from #48493, which added the pre-index data checks that read
SHOW block_size.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
Both runs use the published
ghcr.io/berriai/litellm:main-latestimage (sha256:f38bf0888c091db9079396e17fc8f028d6b75cd26c3e8cb45c5fbdd1f3b66f87, litellm 1.111.0.dev4) started the way the image starts, againstpostgres:16-alpine. Thelitellm_proxy_extraspackage, where the bug lives, comes from source and goes first onPYTHONPATH, so the code that runs is the merge base or this PR's tip. No provider calls are involved, since the failure happens at startup before any request.Shared setup
config.yamlEnv vars set:
DATABASE_URL,PYTHONPATH,POSTGRES_PASSWORD,POSTGRES_DB,POSTGRES_INITDB_ARGS.Before (0cc072c)
SHOW server_encodingon the database returnsSQL_ASCII/key/generateworks, but the log showsLiteLLM_SpendLogs_api_key_startTime_idx,LiteLLM_SpendLogs_litellm_call_id_idxandLiteLLM_DailyUserSpend_api_key_date_idxare all missingAfter (c152707)
SHOW server_encodingon the database returnsSQL_ASCII/key/generateworks, and the log has no request-log index exceptionindisvalid = trueThe same After run on a UTF8 database (
POSTGRES_INITDB_ARGS="--encoding=UTF8") also builds all three, as it did before this PR.Tests, at the tip, in a clean Python 3.13 container with
psycopg[binary]and pytestOn the merge base with only the new test,
test_a_sql_ascii_database_gets_the_same_findings_and_settings_back_as_a_utf8_one[sql-ascii-database]fails withValueError: invalid literal for int() with base 10: "b'8192'"(1 failed, 49 passed). With the fix, 50 passed.ruff check,ruff format --check,ruff_strict_gate.py,type_discipline_gate.pyandtest_quality_gate.pypass at the tip.Type
🐛 Bug Fix
✅ Test
Caveats (if any)
Low
litellm_proxy_extrasreads may still see bytes on SQL_ASCIIrequest_log_indexes.pychild partition names, partitioned tables onlyutils.pyfailed-migration logs, which then print empty_text()replaces undecodable bytes instead of raisingopenapi_docs_gate.pyandtype_check_gate.pywere left to CI hereFinal Attestation