Repository navigation
fix: stop a cleared Organization field from failing key creation - #39316
yassin-berriai merged 6 commits into
Conversation
Clearing the Organization combobox in the Create Key modal left organization_id set to an empty string, so /key/generate looked up an organization named "" and failed with "Organization doesn't exist in db. Organization=". OrganizationDropdown now emits null on clear, and GenerateKeyRequest normalizes an empty organization_id or project_id to None the same way it already does for team_id. Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
|
|
|
PR #39316 has no labels (no |
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
Greptile SummaryThe PR normalizes cleared organization and project identifiers so key creation treats them as unset.
Confidence Score: 5/5The PR appears safe to merge. No blocking failure remains.
|
| Filename | Overview |
|---|---|
| litellm/proxy/_types.py | Extends empty-string normalization from team IDs to organization and project IDs. |
| tests/test_litellm/proxy/management_endpoints/test_key_management_endpoints.py | Verifies cleared scope IDs are omitted while valid IDs remain unchanged; the previously flagged customer-specific docstring has been removed without weakening assertions. |
| ui/litellm-dashboard/src/components/common_components/OrganizationDropdown.tsx | Emits null when the organization selection is cleared. |
| ui/litellm-dashboard/src/components/common_components/OrganizationDropdown.test.tsx | Covers the dropdown’s null-on-clear contract. |
| ui/litellm-dashboard/src/components/organisms/create_key_button.tsx | Maps a cleared organization selection to an unset create-key form field. |
| ui/litellm-dashboard/src/components/templates/key_edit_view.tsx | Adapts the key-edit organization handler to the dropdown’s nullable callback contract. |
Reviews (2): Last reviewed commit: "test: drop customer-specific docstring f..." | Re-trigger Greptile
… test Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
|
@greptileai please re-review, the flagged test docstring was removed in af97cc0 |
…itellm_fix_create_key_empty_org_id
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
…mpty_org_id Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
…_id' Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
TLDR
Problem this solves:
Organization doesn't exist in db. Organization=How it solves it:
OrganizationDropdownemitsnullon clear instead of""/key/generatetreatsproject_id: ""as unset, liketeam_idandorganization_idorganization_idhalf landed on base in fix: 1.99.0-rc2 UI bug batch (empty org on key create, session pagination, access group rename/delete) #39436; this PR addsproject_idand the dropdown contract on topUser Flow
Before: an admin who picks an organization and then changes their mind cannot create the key
Error creating the key: Error: Organization doesn't exist in db. Organization=. Create organization via /organization/new call.and no key is createdAfter: the same steps create a personal key with no organization
sk-...key and the key list shows it with no organizationRelevant issues
Reported by a customer on 1.99.0-rc2 (Pylon #8102)
Linear ticket
Resolves LIT-6683
Pre-Submission checklist
Please complete all items before asking a LiteLLM maintainer to review your PR
uv run pytest tests/test_litellm/<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
Proxy started locally with
uv run litellm --config litellm/proxy/dev_config.yaml --port 4000against a local Postgres. The request body below is exactly what the Create Key modal sends after the Organization field is clearedBefore (31ca4dd)
curl -s -X POST localhost:4000/key/generate -H 'Authorization: Bearer sk-1234' -H 'Content-Type: application/json' -d '{"organization_id": ""}'{"error":{"message":"Organization doesn't exist in db. Organization=. Create organization via/organization/newcall.","type":"internal_server_error","param":"None","code":"500"}}After (6d88e7b; later commits only merge litellm_internal_staging, which fixed the
organization_idhalf independently in #39436, so the request below still returns the same result)curl -s -X POST localhost:4000/key/generate -H 'Authorization: Bearer sk-1234' -H 'Content-Type: application/json' -d '{"organization_id": "", "project_id": "", "key_alias": "pylon8102-after-1"}'200with"key": "sk-gn5f...", "organization_id": null, "project_id": null, "team_id": null, "key_alias": "pylon8102-after-1"curl -s -X POST localhost:4000/key/generate -H 'Authorization: Bearer sk-1234' -H 'Content-Type: application/json' -d '{"organization_id": "org-does-not-exist"}'{"error":{"message":"Organization doesn't exist in db. Organization=org-does-not-exist. Create organization via/organization/newcall.", ... "code":"500"}}UI check for a reviewer: run
npm run devinui/litellm-dashboard, open http://localhost:3000/ui/?page=api-keys, Create New Key, pick an organization, clear it with the x button, set an alias, Create Key. The key is created instead of theOrganization=errorType
🐛 Bug Fix
Caveats (if any)
Low
project_id: ""normalization plus the dropdown'snull-on-clear contract;organization_idnormalization and the key editnull-on-clear write come from fix: 1.99.0-rc2 UI bug batch (empty org on key create, session pagination, access group rename/delete) #39436Final Attestation
Link to Devin session: https://app.devin.ai/sessions/07bfcc2b38864e0a8b5ddc506634111a
Open in Devin Desktop: https://app.devin.ai/desktop/session/07bfcc2b38864e0a8b5ddc506634111a?variant=devin
Requested by: @yassin-berriai
CI Status
Link to Devin session: https://app.devin.ai/sessions/ef392a8b1fe2494691ef39ec5f97b2d5
Open in Devin Desktop: https://app.devin.ai/desktop/session/ef392a8b1fe2494691ef39ec5f97b2d5?variant=devin