From cde23e9b6eaea89e43f07ef4b7393cd1a424e93b Mon Sep 17 00:00:00 2001 From: yuneng-jiang Date: Thu, 26 Feb 2026 20:53:30 -0800 Subject: [PATCH] fix: normalize null list fields to [] in update_data before DB write When a client sends null for assigned_team_ids or assigned_key_ids, ensure the DB receives [] instead of null, preventing null from being stored where empty list is expected. Extend test to verify the DB call uses []. Co-Authored-By: Claude Sonnet 4.6 --- .../proxy/management_endpoints/access_group_endpoints.py | 2 ++ .../management_endpoints/test_access_group_endpoints.py | 7 ++++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/litellm/proxy/management_endpoints/access_group_endpoints.py b/litellm/proxy/management_endpoints/access_group_endpoints.py index 7e75060e87..53dfbcda83 100644 --- a/litellm/proxy/management_endpoints/access_group_endpoints.py +++ b/litellm/proxy/management_endpoints/access_group_endpoints.py @@ -392,6 +392,8 @@ async def update_access_group( update_fields = data.model_dump(exclude_unset=True) update_data: dict = {"updated_by": user_api_key_dict.user_id} for field, value in update_fields.items(): + if field in ("assigned_team_ids", "assigned_key_ids") and value is None: + value = [] update_data[field] = value # Initialize delta lists before the try block so they remain accessible diff --git a/tests/test_litellm/proxy/management_endpoints/test_access_group_endpoints.py b/tests/test_litellm/proxy/management_endpoints/test_access_group_endpoints.py index fc3c87a112..32fd0750de 100644 --- a/tests/test_litellm/proxy/management_endpoints/test_access_group_endpoints.py +++ b/tests/test_litellm/proxy/management_endpoints/test_access_group_endpoints.py @@ -1169,7 +1169,7 @@ def test_delete_access_group_handles_out_of_sync_assigned_keys(client_and_mocks) def test_update_access_group_null_assigned_ids_treated_as_empty(client_and_mocks): - """Update with explicit null for assigned_*_ids clears the list without TypeError.""" + """Update with explicit null for assigned_*_ids clears the list and writes [] to DB.""" client, _, mock_table, *_ = client_and_mocks existing = _make_access_group_record( @@ -1185,3 +1185,8 @@ def test_update_access_group_null_assigned_ids_treated_as_empty(client_and_mocks json={"assigned_team_ids": None, "assigned_key_ids": None}, ) assert resp.status_code == 200 + + # Verify the DB update was called with [] (not null) for list fields + update_call_kwargs = mock_table.update.call_args.kwargs + assert update_call_kwargs["data"]["assigned_team_ids"] == [] + assert update_call_kwargs["data"]["assigned_key_ids"] == []