langfuse-python
langfuse-python copied to clipboard
fix(prompts): handle httpx encoding for prompt name in updates
[!IMPORTANT] Fixes URL encoding for prompt names in
update_prompt()inclient.pyto ensure compatibility withhttpx0.28.0+.
- Behavior:
- Fixes URL encoding for prompt names in
update_prompt()inclient.pyby settingis_url_param=Truein_url_encode().- Ensures compatibility with
httpxversion 0.28.0 and above, preventing double-encoding issues.This description was created by
for 0efa27312223fcb66db5e606d718204b9eb5b795. You can customize this summary. It will automatically update as commits are pushed.
Disclaimer: Experimental PR review
Greptile Overview
Greptile Summary
Fixed double-encoding bug in update_prompt method by adding the is_url_param=True flag to the _url_encode call. This ensures prompt names (especially those in folders with slashes) are correctly encoded when sent to the API.
- Added
is_url_param=Trueparameter to_url_encode()call inupdate_promptmethod - Aligns with the existing pattern used in other methods like
dataset_items.list() - Prevents double-encoding when httpx ≥0.28 handles URL encoding automatically
- Fixes consistency issue where
update_promptwas manually encoding path parameters while httpx would also encode them
Confidence Score: 5/5
- This PR is safe to merge with minimal risk
- The change is a single-line fix that adds a missing parameter to prevent double-encoding, follows existing patterns in the codebase, and aligns with how other similar methods handle URL encoding for httpx path parameters
- No files require special attention
Important Files Changed
File Analysis
| Filename | Score | Overview |
|---|---|---|
| langfuse/_client/client.py | 5/5 | Added is_url_param=True flag to _url_encode call in update_prompt method to prevent double-encoding with httpx ≥0.28 |
Sequence Diagram
sequenceDiagram
participant Client as Langfuse Client
participant URLEncode as _url_encode()
participant API as prompt_version.update()
participant HTTPX as httpx client
participant Server as Langfuse API
Client->>URLEncode: _url_encode(name, is_url_param=True)
alt httpx >= 0.28.0
URLEncode-->>Client: name (unencoded)
Note over URLEncode: Skip encoding, httpx will handle it
else httpx < 0.28.0
URLEncode->>URLEncode: urllib.parse.quote(name, safe="")
URLEncode-->>Client: encoded_name
Note over URLEncode: Manual encoding for older httpx
end
Client->>API: update(name, version, new_labels)
API->>HTTPX: PATCH /api/public/v2/prompts/{name}/versions/{version}
Note over HTTPX: httpx >= 0.28 applies WHATWG-compliant encoding
HTTPX->>Server: HTTP Request
Server-->>HTTPX: Response
HTTPX-->>API: Prompt object
API-->>Client: updated_prompt