mirror of
https://github.com/BerriAI/litellm.git
synced 2026-10-09 03:18:44 +00:00
fix(vertex/files): keep legacy bucket_name as GCS bucket fallback
The rename to gcs_bucket_name dropped the legacy bucket_name key entirely, so an SDK caller passing bucket_name to a Vertex AI file create/retrieve/content call with GCS_BUCKET_NAME unset got ValueError("GCS bucket_name is required") where it previously resolved the bucket. _get_configured_bucket_name now reads gcs_bucket_name, then bucket_name, then the env var, and bucket_name is restored to OPTIONAL_KWARGS_KEYS so it survives get_litellm_params on the retrieve and content paths. gcs_bucket_name keeps precedence when both are present
This commit is contained in:
parent
26dc0e9943
commit
d0397979b5
3 changed files with 49 additions and 2 deletions
|
|
@ -15,6 +15,7 @@ OPTIONAL_KWARGS_KEYS = frozenset(
|
|||
"azure_scope",
|
||||
"timeout",
|
||||
"gcs_bucket_name",
|
||||
"bucket_name",
|
||||
"vertex_credentials",
|
||||
"vertex_project",
|
||||
"vertex_location",
|
||||
|
|
|
|||
|
|
@ -360,8 +360,10 @@ class VertexAIFilesConfig(VertexBase, BaseFilesConfig):
|
|||
)
|
||||
|
||||
def _get_configured_bucket_name(self, litellm_params: Dict) -> str:
|
||||
bucket_name = litellm_params.get("gcs_bucket_name") or os.getenv(
|
||||
"GCS_BUCKET_NAME"
|
||||
bucket_name = (
|
||||
litellm_params.get("gcs_bucket_name")
|
||||
or litellm_params.get("bucket_name")
|
||||
or os.getenv("GCS_BUCKET_NAME")
|
||||
)
|
||||
if not bucket_name:
|
||||
raise ValueError("GCS bucket_name is required")
|
||||
|
|
|
|||
|
|
@ -1274,3 +1274,47 @@ class TestVertexBatchCustomIdLabels:
|
|||
raw_label = vertex_input[0]["request"]["labels"]["litellm_custom_id_raw"]
|
||||
assert raw_label != "MyRequest-1"
|
||||
assert _sanitize_gcp_label_value(raw_label) == raw_label
|
||||
|
||||
|
||||
class TestConfiguredBucketNameResolution:
|
||||
def test_should_resolve_new_gcs_bucket_name_key(self, config, monkeypatch):
|
||||
monkeypatch.delenv("GCS_BUCKET_NAME", raising=False)
|
||||
assert (
|
||||
config._get_configured_bucket_name({"gcs_bucket_name": "my-new-bucket"})
|
||||
== "my-new-bucket"
|
||||
)
|
||||
|
||||
def test_should_resolve_legacy_bucket_name_key(self, config, monkeypatch):
|
||||
monkeypatch.delenv("GCS_BUCKET_NAME", raising=False)
|
||||
assert (
|
||||
config._get_configured_bucket_name({"bucket_name": "my-legacy-bucket"})
|
||||
== "my-legacy-bucket"
|
||||
)
|
||||
|
||||
def test_should_prefer_new_key_over_legacy(self, config, monkeypatch):
|
||||
monkeypatch.delenv("GCS_BUCKET_NAME", raising=False)
|
||||
assert (
|
||||
config._get_configured_bucket_name(
|
||||
{"gcs_bucket_name": "new", "bucket_name": "legacy"}
|
||||
)
|
||||
== "new"
|
||||
)
|
||||
|
||||
def test_should_fall_back_to_env(self, config, monkeypatch):
|
||||
monkeypatch.setenv("GCS_BUCKET_NAME", "env-bucket")
|
||||
assert config._get_configured_bucket_name({}) == "env-bucket"
|
||||
|
||||
def test_should_raise_when_no_bucket_anywhere(self, config, monkeypatch):
|
||||
monkeypatch.delenv("GCS_BUCKET_NAME", raising=False)
|
||||
with pytest.raises(ValueError, match="GCS bucket_name is required"):
|
||||
config._get_configured_bucket_name({})
|
||||
|
||||
def test_legacy_kwarg_survives_get_litellm_params(self):
|
||||
from litellm.litellm_core_utils.get_litellm_params import (
|
||||
OPTIONAL_KWARGS_KEYS,
|
||||
get_litellm_params,
|
||||
)
|
||||
|
||||
assert "bucket_name" in OPTIONAL_KWARGS_KEYS
|
||||
params = get_litellm_params(bucket_name="my-legacy-bucket")
|
||||
assert params.get("bucket_name") == "my-legacy-bucket"
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue