Repository navigation
fix(credentials): keep credential labels and edits consistent across UI, API, and replicas - #45835
Conversation
…UI, API, and replicas The credential modal flattened stored credential values into the same form object as the credential's own name, label, and provider, so a stored value keyed credential_name or display_name replaced the real one and the edit went to the wrong credential or relabeled it. The modal now submits the top-level fields and credential_values separately PATCH /credentials now reads the row it merges onto from the writer, so an edit inside the read replica's lag window no longer writes back an older label or key POST /credentials answers 409 for a name defined in config instead of creating a DB copy that shadows it display_name rules live on the server only. It rejects control, formatting, and line separator characters, and the UI stops enforcing its own length check and shows the server's error The models table, model detail view, and model edit picker show the credential's technical name under its label whenever the two differ
|
Merging this PR will not alter performance
|
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
The config marker sat under the credential name. The credentials table now has a Source column with a Config or DB status badge, matching the Source column on the models table
…ull credential name on hover Moves displayNameChange and initialFormValues out of the modal so their rules are unit tested, keeps only the wiring cases in the modal's integration test, makes the label acceptance test write through the real credentials repository, and adds the full credential name as a hover title where the models pages truncate it
|
@greptileai please review the latest commits, which address all three findings from the previous pass. |
TLDR
Problem this solves:
How it solves it:
Intentional product change: the dashboard no longer trims or length-checks the label before saving, so a label of only spaces now shows the server's "cannot be blank" error instead of clearing the label (clear it by emptying the field). POST /credentials with the name of a config.yaml credential now returns 409 instead of creating a DB copy that overrides it
User Flow
Before: an admin saves an untouched credential and the dashboard relabels a different one
legacy-a(label "Legacy A") has stored values that happen to includecredential_name: label-probeanddisplay_name: Inner labellabel-probeand Display Name "Inner label"label-proberelabeled "Inner label"After: the same save stays on the credential the admin opened
legacy-acredential with the same stored valueslegacy-aand Display Name "Legacy A"label-probeis unchangedBefore: the models table names a credential only by its label, so a reader cannot tell which credential a model uses
proof-openaihas the label "Relabeled" and modeldb-modeluses itdb-modelshows only "Relabeled"After: the column shows the label with the credential name under it
db-modelshows "Relabeled" withproof-openaibeneath it in muted text. The model detail view, the model edit picker, and the "Using Existing Credential" dialog do the sameBefore: the credential list shows a config credential as editable after a POST shadowed it, and a stored
Prod\u202eAIlabel (U+202E, right-to-left override) renders reversed as "ProdIA". After: the POST was refused, socfg-openaistill shows Config in the new Source column, and the reversing label was rejectedRelevant issues
Follows up on #43148
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 more@greptileaito re-request a review after pushing changes)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
Both proxies ran side by side against one local Postgres with separate databases, real OpenAI calls through
openai/gpt-5.4-nano, and dotenv turned off so neither inherits stray env (LITELLM_MODE=PRODUCTION STORE_MODEL_IN_DB=True). Before is a worktree at the merge base on :4011, After is this branch on :4012, and the dashboard dev servers are :3005 and :3006create-proof-openai.jsonis{"credential_name": "proof-openai", "display_name": "Original", "credential_values": {"api_key": "<real OpenAI key>", "api_base": "https://api.openai.com/v1"}, "credential_info": {"custom_llm_provider": "openai"}}andcreate-label-probe.jsonis the same shape forlabel-probewith only an api key. The proxy env carries noOPENAI_API_KEY, so a request can only succeed through a credentialFor the replica case each proxy was stopped, its database was copied with
CREATE DATABASE <db>_replica TEMPLATE <db>, and the proxy was restarted withDATABASE_URL_READ_REPLICApointing at that copy. The copy never receives later writes, which is a replica stuck at the start of its lag windowBefore (38d0333)
POST over a config.yaml credential
curl -s -X POST localhost:4011/credentials -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H "Content-Type: application/json" -d '{"credential_name": "cfg-openai", "credential_values": {"api_key": "sk-not-a-real-key"}, "credential_info": {"custom_llm_provider": "openai"}}'curl -s localhost:4011/chat/completions -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H "Content-Type: application/json" -d '{"model": "cfg-model", "messages": [{"role": "user", "content": "Reply with the single word ok"}]}'Invisible and text-reversing label characters
curl -s -X PATCH localhost:4011/credentials/label-probe -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H "Content-Type: application/json" -d '{"display_name": "\u200b", "credential_info": {}}'curl -s -X PATCH localhost:4011/credentials/label-probe -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H "Content-Type: application/json" -d '{"display_name": "Prod\u202eAI", "credential_info": {}}'The credential list then renders it as "ProdIA" (see the credential list screenshot under User Flow)
Edit right after a relabel, with a lagging read replica
curl -s -X PATCH localhost:4011/credentials/proof-openai -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H "Content-Type: application/json" -d '{"display_name": "Relabeled", "credential_info": {}}'curl -s -X PATCH localhost:4011/credentials/proof-openai -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H "Content-Type: application/json" -d '{"credential_values": {"api_base": "https://api.openai.com/v1/"}, "credential_info": {}}'psql -h 127.0.0.1 -p 55432 -U postgres -d proof_before -Atc "select display_name from \"LiteLLM_CredentialsTable\" where credential_name = 'proof-openai'"curl -s localhost:4011/chat/completions -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H "Content-Type: application/json" -d '{"model": "db-model", "messages": [{"role": "user", "content": "Reply with the single word ok"}]}'Saving a credential whose stored values reuse top-level names
label-probe, and Update Credential sendsPATCH http://localhost:4011/credentials/label-probe(200), relabelinglabel-probeto "Inner label"Models table credential column
db-modelrow shows only "Relabeled" (screenshot under User Flow)After (c9989b1)
POST over a config.yaml credential
curl -s -X POST localhost:4012/credentials -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H "Content-Type: application/json" -d '{"credential_name": "cfg-openai", "credential_values": {"api_key": "sk-not-a-real-key"}, "credential_info": {"custom_llm_provider": "openai"}}'curl -s localhost:4012/chat/completions -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H "Content-Type: application/json" -d '{"model": "cfg-model", "messages": [{"role": "user", "content": "Reply with the single word ok"}]}'Invisible and text-reversing label characters
curl -s -X PATCH localhost:4012/credentials/label-probe -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H "Content-Type: application/json" -d '{"display_name": "\u200b", "credential_info": {}}'curl -s -X PATCH localhost:4012/credentials/label-probe -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H "Content-Type: application/json" -d '{"display_name": "Prod\u202eAI", "credential_info": {}}'Edit right after a relabel, with a lagging read replica
curl -s -X PATCH localhost:4012/credentials/proof-openai -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H "Content-Type: application/json" -d '{"display_name": "Relabeled", "credential_info": {}}'curl -s -X PATCH localhost:4012/credentials/proof-openai -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H "Content-Type: application/json" -d '{"credential_values": {"api_base": "https://api.openai.com/v1/"}, "credential_info": {}}'psql -h 127.0.0.1 -p 55432 -U postgres -d proof_after -Atc "select display_name from \"LiteLLM_CredentialsTable\" where credential_name = 'proof-openai'"curl -s localhost:4012/chat/completions -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H "Content-Type: application/json" -d '{"model": "db-model", "messages": [{"role": "user", "content": "Reply with the single word ok"}]}'Saving a credential whose stored values reuse top-level names
legacy-a, and Update Credential sendsPATCH http://localhost:4012/credentials/legacy-a(200), leavinglabel-probeuntouchedModels table credential column
db-modelrow shows "Relabeled" withproof-openaiunder it (screenshot under User Flow)Type
🐛 Bug Fix
Caveats (if any)
Medium
Low