litellm icon indicating copy to clipboard operation
litellm copied to clipboard

Proxy start crashes with ValueError in find_blockers when the database encoding is SQL_ASCII

Open lusoris opened this issue 2 weeks ago • 4 comments

On a PostgreSQL database created with encoding SQL_ASCII, the proxy exits at start while building the request-log indexes: find_blockers in migration_data_checks.py raises ValueError: invalid literal for int() with base 10: "b'8192'".

Version: v1.109.1 (ghcr.io/berriai/litellm-non_root:v1.109.1). The same lines are on main today: the file moved to litellm/proxy-extras/litellm_proxy_extras/, and its content is byte-identical to the tag.

Cause

  • migration_data_checks.py line 347 reads SHOW block_size through psycopg, and line 348 converts it with int(str(block_size[0])).
  • psycopg does not decode text when the connection encoding is SQL_ASCII and returns bytes instead (psycopg docs, "Strings adaptation"). str(b'8192') is the text b'8192', so int() fails.
  • Lines 362 and 366 use the same str(row[0]) pattern for statement_timeout and default_transaction_read_only, so they would hand b'0' and b'off' back to SET on the same databases. This is inferred from the same pattern; we have not reproduced it.

How we hit it

A start-up smoke test ran the image against a throwaway database made with a bare initdb in an image without LANG, which picks encoding SQL_ASCII. The traceback ends in request_log_indexes.py build → find_blockers line 348. Databases created with UTF8 start normally, so most deployments never see this.

Possible fix

Decode bytes before converting, for example value.decode() if isinstance(value, bytes) else str(value) in one helper used by lines 348, 362 and 366, or read the settings with current_setting(...)::int / ::text casts so psycopg returns typed values. A unit test with a fake cursor returning b'8192' would cover it.

lusoris avatar Nov 17 '26 07:11 lusoris

Could I work on decoding PostgreSQL settings consistently, with SQL_ASCII and UTF8 startup regressions covering block size and session-setting restoration?

GoyalIshaan avatar Nov 17 '26 07:11 GoyalIshaan

I’d also be glad to help with this if it’s still available

afeefaa333 avatar Nov 17 '26 09:11 afeefaa333

I’ve opened a PR with a fix and regression test for this issue

afeefaa333 avatar Nov 17 '26 20:11 afeefaa333

Hi @lusoris, the fix is merged. Thanks for reporting this!

I'd love to hear how you're using LiteLLM and what we could make better for you.

If you're up for it, book a 30-minute chat with me, or connect with me on LinkedIn. I'd be happy to hear what's working and what's frustrating, no prep needed.

kenneth-berri avatar Nov 24 '26 00:11 kenneth-berri