Skip to content

fix: stop a cleared Organization field from failing key creation - #39316

Merged
yassin-berriai merged 6 commits into
litellm_internal_stagingfrom
litellm_fix_create_key_empty_org_id
Sep 3, 2026
Merged

yassin-berriai merged 6 commits into
litellm_internal_stagingfrom
litellm_fix_create_key_empty_org_id

Conversation

@devin-ai-integration

@devin-ai-integration devin-ai-integration Bot commented Sep 2, 2026 •

Copy link
Copy Markdown
Contributor

TLDR

Problem this solves:

  • Clearing the Organization field in Create Key fails the request
  • Error shown: Organization doesn't exist in db. Organization=
  • Regression since the shadcn dropdown migration (1.98.0+)

How it solves it:

User Flow

Before: an admin who picks an organization and then changes their mind cannot create the key

  1. They open https://litellm-domain/ui/?page=api-keys and click Create New Key
  2. They select an organization in the Organization field, then click the field's clear (x) button
  3. They fill in a key alias and click Create Key
  4. The modal shows Error creating the key: Error: Organization doesn't exist in db. Organization=. Create organization via /organization/new call. and no key is created

After: the same steps create a personal key with no organization

  1. They open https://litellm-domain/ui/?page=api-keys and click Create New Key
  2. They select an organization in the Organization field, then click the field's clear (x) button
  3. They fill in a key alias and click Create Key
  4. The modal shows the new sk-... key and the key list shows it with no organization

Relevant 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

  • I have added meaningful tests
  • The handful of test files covering my change pass locally, e.g. 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
  • My PR passes all required CI/CD checks (e.g., lint, schema.d.ts sync check, etc.)
  • My PR's scope is as isolated as possible; it only solves 1 specific problem
  • I have received a Greptile Confidence Score of at least 4/5 before requesting a maintainer review (Greptile reviews automatically once the PR is opened; only comment @greptileai to 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 4000 against a local Postgres. The request body below is exactly what the Create Key modal sends after the Organization field is cleared

Before (31ca4dd)

  1. curl -s -X POST localhost:4000/key/generate -H 'Authorization: Bearer sk-1234' -H 'Content-Type: application/json' -d '{"organization_id": ""}'
  2. {"error":{"message":"Organization doesn't exist in db. Organization=. Create organization via /organization/new call.","type":"internal_server_error","param":"None","code":"500"}}

After (6d88e7b; later commits only merge litellm_internal_staging, which fixed the organization_id half independently in #39436, so the request below still returns the same result)

  1. 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"}'
  2. 200 with "key": "sk-gn5f...", "organization_id": null, "project_id": null, "team_id": null, "key_alias": "pylon8102-after-1"
  3. Sanity check that a real but unknown org is still rejected: 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"}'
  4. {"error":{"message":"Organization doesn't exist in db. Organization=org-does-not-exist. Create organization via /organization/new call.", ... "code":"500"}}

UI check for a reviewer: run npm run dev in ui/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 the Organization= error

Type

🐛 Bug Fix

Caveats (if any)

Low

Final Attestation

  • The tests check the right things, including the edge cases, and regressions in the respective real-world customer use-cases are not possible after this PR

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

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-integration

Copy link
Copy Markdown
Contributor Author

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR. Add '(aside)' to your comment to have me ignore it.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment, CI, and merge conflict monitoring

@CLAassistant

CLAassistant commented Sep 2, 2026 •

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you all sign our Contributor License Agreement before we can accept your contribution.
0 out of 2 committers have signed the CLA.

❌ yassin-berriai
❌ devin-ai-integration[bot]
You have signed the CLA already but the status is still pending? Let us recheck it.

@devin-ai-integration

Copy link
Copy Markdown
Contributor Author

PR #39316 has no labels (no enterprise label), so it is out of scope. No changes made; exiting.

@codspeed

codspeed Bot commented Sep 2, 2026 •

Copy link
Copy Markdown
Contributor

Merging this PR will not alter performance

✅ 31 untouched benchmarks


Comparing litellm_fix_create_key_empty_org_id (9129092) with litellm_internal_staging (e046aee)

Open in CodSpeed

@codecov

codecov Bot commented Sep 2, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@greptile-apps

greptile-apps Bot commented Sep 2, 2026 •

Copy link
Copy Markdown
Contributor

Greptile Summary

The PR normalizes cleared organization and project identifiers so key creation treats them as unset.

  • Updates proxy request validation to convert empty scope IDs to None.
  • Updates the organization dropdown and form handlers to represent cleared selections consistently.
  • Adds backend and UI regression coverage for cleared organization and project fields.

Confidence Score: 5/5

The PR appears safe to merge.

No blocking failure remains.

Important Files Changed

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

Comment thread tests/test_litellm/proxy/management_endpoints/test_key_management_endpoints.py Outdated
… test

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@devin-ai-integration

Copy link
Copy Markdown
Contributor Author

@greptileai please re-review, the flagged test docstring was removed in af97cc0

@yassin-berriai
yassin-berriai enabled auto-merge (squash) September 3, 2026 18:56
yassin-berriai and others added 3 commits September 3, 2026 18:59
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>
@yassin-berriai
yassin-berriai merged commit 9212208 into litellm_internal_staging Sep 3, 2026
80 checks passed
@yassin-berriai
yassin-berriai deleted the litellm_fix_create_key_empty_org_id branch September 3, 2026 19:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants