mirror of
https://github.com/BerriAI/litellm.git
synced 2026-10-03 02:22:24 +00:00
fix(mcp): compute per-user env var lock key without hashtextextended
pg_advisory_xact_lock keyed via hashtextextended requires PostgreSQL 11+; older clusters fail on every merge_user_env_vars call. Derive a stable 64-bit signed key from (user_id, server_id) with blake2b in Python and pass it straight to pg_advisory_xact_lock, so the lock works on every supported PostgreSQL version and no longer depends on an internal hash function
This commit is contained in:
parent
16f1d3ecb8
commit
3f61004864
1 changed files with 7 additions and 4 deletions
|
|
@ -1,5 +1,6 @@
|
|||
import base64
|
||||
import binascii
|
||||
import hashlib
|
||||
import json
|
||||
from datetime import datetime, timedelta, timezone
|
||||
from typing import Any, Dict, Iterable, List, Optional, Set, Union, cast
|
||||
|
|
@ -1272,11 +1273,13 @@ async def merge_user_env_vars(
|
|||
so an admin retiring a user-scoped variable also clears its stored value.
|
||||
"""
|
||||
allowed = set(allowed_names)
|
||||
lock_key = int.from_bytes(
|
||||
hashlib.blake2b(f"{user_id}:{server_id}".encode(), digest_size=8).digest(),
|
||||
"big",
|
||||
signed=True,
|
||||
)
|
||||
async with prisma_client.db.tx() as tx:
|
||||
await tx.query_raw(
|
||||
"SELECT pg_advisory_xact_lock(hashtextextended($1, 0))",
|
||||
f"{user_id}:{server_id}",
|
||||
)
|
||||
await tx.query_raw("SELECT pg_advisory_xact_lock($1::bigint)", lock_key)
|
||||
row = await tx.litellm_mcpuserenvvars.find_unique(
|
||||
where={"user_id_server_id": {"user_id": user_id, "server_id": server_id}}
|
||||
)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue