mirror of
https://github.com/BerriAI/litellm.git
synced 2026-09-13 23:11:40 +00:00
Merge ed6f8216d8 into 1c61c2606e
This commit is contained in:
commit
8ee1808ef7
2 changed files with 34 additions and 1 deletions
|
|
@ -125,7 +125,6 @@ func (c *Client) UpdateKey(key *Key) (*Key, error) {
|
|||
// Create a new map with only the fields that can be updated
|
||||
updateData := map[string]interface{}{
|
||||
"key": key.Key,
|
||||
"team_id": key.TeamID,
|
||||
"key_alias": key.KeyAlias,
|
||||
"aliases": key.Aliases,
|
||||
"permissions": key.Permissions,
|
||||
|
|
@ -144,6 +143,12 @@ func (c *Client) UpdateKey(key *Key) (*Key, error) {
|
|||
updateData["model_tpm_limit"] = key.ModelTPMLimit
|
||||
}
|
||||
|
||||
// The proxy rejects an empty team_id with a 500 ("Team object not found"),
|
||||
// so only send it when set.
|
||||
if key.TeamID != "" {
|
||||
updateData["team_id"] = key.TeamID
|
||||
}
|
||||
|
||||
// The proxy rejects an empty-string budget_duration with a 400, so only
|
||||
// send it when set.
|
||||
if key.BudgetDuration != "" {
|
||||
|
|
|
|||
|
|
@ -319,6 +319,34 @@ func TestUpdateKeyOmitsEmptyBudgetDuration(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
// The proxy 500s on team_id: "" with "Team object not found", so a teamless key
|
||||
// must omit it from the update payload entirely.
|
||||
func TestUpdateKeyOmitsEmptyTeamID(t *testing.T) {
|
||||
var captured map[string]interface{}
|
||||
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
body, _ := io.ReadAll(r.Body)
|
||||
json.Unmarshal(body, &captured)
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
w.Write([]byte(`{"key": "sk-test"}`))
|
||||
}))
|
||||
defer srv.Close()
|
||||
|
||||
client := NewClient(srv.URL, "test-key", true)
|
||||
if _, err := client.UpdateKey(&Key{Key: "sk-test"}); err != nil {
|
||||
t.Fatalf("UpdateKey returned error: %v", err)
|
||||
}
|
||||
if _, present := captured["team_id"]; present {
|
||||
t.Errorf("update payload contains empty team_id: %v", captured["team_id"])
|
||||
}
|
||||
|
||||
if _, err := client.UpdateKey(&Key{Key: "sk-test", TeamID: "team-1"}); err != nil {
|
||||
t.Fatalf("UpdateKey returned error: %v", err)
|
||||
}
|
||||
if captured["team_id"] != "team-1" {
|
||||
t.Errorf("team_id = %v, want team-1", captured["team_id"])
|
||||
}
|
||||
}
|
||||
|
||||
func TestResourceKeyUpdateFailureKeepsPriorState(t *testing.T) {
|
||||
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue