fix: make sure gcs_bucket_name passes#20491
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Greptile OverviewGreptile SummaryThis PR adds support for passing Key Changes:
Issues Found:
Confidence Score: 2/5
|
| Filename | Overview |
|---|---|
| litellm/llms/vertex_ai/files/transformation.py | Added fallback to retrieve gcs_bucket_name from litellm_metadata, but uses .pop() which mutates the dictionary |
| litellm/router.py | Added logic to pass gcs_bucket_name through litellm_metadata, potential KeyError risk if dictionary not initialized |
Sequence Diagram
sequenceDiagram
participant Client
participant Router
participant LiteLLM
participant VertexAIConfig
participant GCS
Client->>Router: acreate_file(gcs_bucket_name="my-bucket", ...)
Router->>Router: create_file_for_deployment()
Router->>Router: _update_kwargs_with_deployment()<br/>(initializes litellm_metadata)
alt gcs_bucket_name in data
Router->>Router: kwargs_copy["litellm_metadata"]["gcs_bucket_name"] = data["gcs_bucket_name"]
end
Router->>LiteLLM: litellm.acreate_file(**data, **kwargs_copy)
LiteLLM->>VertexAIConfig: get_complete_file_url(litellm_params)
VertexAIConfig->>VertexAIConfig: Check bucket_name sources:<br/>1. litellm_params.get("bucket_name")<br/>2. litellm_params.get("litellm_metadata", {}).pop("gcs_bucket_name")<br/>3. os.getenv("GCS_BUCKET_NAME")
Note over VertexAIConfig: ⚠️ .pop() mutates litellm_metadata!<br/>Subsequent access will fail
VertexAIConfig->>LiteLLM: Return GCS URL
LiteLLM->>GCS: Upload file to GCS bucket
GCS->>LiteLLM: File uploaded
LiteLLM->>Router: File object
Router->>Client: File object
| Get the complete url for the request | ||
| """ | ||
| bucket_name = litellm_params.get("bucket_name") or os.getenv("GCS_BUCKET_NAME") | ||
| bucket_name = litellm_params.get("bucket_name") or litellm_params.get("litellm_metadata", {}).pop("gcs_bucket_name", None) or os.getenv("GCS_BUCKET_NAME") |
There was a problem hiding this comment.
.pop() mutates litellm_metadata by removing the key, which causes issues if litellm_params is reused. Use .get() instead.
| bucket_name = litellm_params.get("bucket_name") or litellm_params.get("litellm_metadata", {}).pop("gcs_bucket_name", None) or os.getenv("GCS_BUCKET_NAME") | |
| bucket_name = litellm_params.get("bucket_name") or litellm_params.get("litellm_metadata", {}).get("gcs_bucket_name") or os.getenv("GCS_BUCKET_NAME") |
Prompt To Fix With AI
This is a comment left during a code review.
Path: litellm/llms/vertex_ai/files/transformation.py
Line: 168:168
Comment:
`.pop()` mutates `litellm_metadata` by removing the key, which causes issues if `litellm_params` is reused. Use `.get()` instead.
```suggestion
bucket_name = litellm_params.get("bucket_name") or litellm_params.get("litellm_metadata", {}).get("gcs_bucket_name") or os.getenv("GCS_BUCKET_NAME")
```
How can I resolve this? If you propose a fix, please make it concise.Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>
|
Hey @Sameerlite, thanks for working on this! I traced through the full call chain and I think there's a much simpler fix available. Root causeThe
The problem is just that line 168 of # Current code — misses the config value:
bucket_name = litellm_params.get("bucket_name") or os.getenv("GCS_BUCKET_NAME")Suggested fixA one-liner in bucket_name = litellm_params.get("bucket_name") or litellm_params.get("gcs_bucket_name") or os.getenv("GCS_BUCKET_NAME")This means you don't need the router-level plumbing through Bug in current PRAlso a heads-up: the Hope this helps! |
|
@jquinter , if you check i have added a Todo in this PR, feel free to do that. Actually the issue is, after step 2, the gcs_bucket_name is not present in step 3. It gets removed in between somewhere but I am not able to pinpoint where. Hence I had added it like this. If you want, you can try this out. That's why i am popping it once i get it, because should not be in there ideally |
Relevant issues
Fixes LIT-1860
Pre-Submission checklist
Please complete all items before asking a LiteLLM maintainer to review your PR
tests/litellm/directory, Adding at least 1 test is a hard requirement - see detailsmake test-unitCI (LiteLLM team)
Branch creation CI run
Link:
CI run for the last commit
Link:
Merge / cherry-pick CI run
Links:
Type
🆕 New Feature
🐛 Bug Fix
🧹 Refactoring
📖 Documentation
🚄 Infrastructure
✅ Test
Changes
How to use: