googleapis / googleapis/python-aiplatform

vertexai.preview.prompts.get() does not populate version_id or version_name when fetching latest version

Đang mở
#6,637 0 bình luận 0 reaction 0 người được giao Xem trên GitHub
api: vertex-ai
Ngôn ngữ chính
Python
Star
905
Fork
465
Merge trung bình
1 ngày 13 giờ
Pull request đã merge (30 ngày)
44

Mô tả

### Environment details

- OS: Linux (Debian, x86-64)
- Python version: 3.13.5
- pip version: pip show pip → 24.x
- google-cloud-aiplatform version: 1.148.1

### Steps to reproduce

1. Create a prompt in Vertex AI with at least one version via vertexai.preview.prompts.create_version()
2. Fetch it without pinning a version: prompts.get(prompt_id="")
3. Inspect prompt.version_id and prompt.version_name

### Code example

```
import vertexai
from vertexai.preview import prompts

vertexai.init(project="my-project", location="us-central1")

# Fetch latest — content is correct, but version is unknown
prompt = prompts.get(prompt_id="123456789")
print(prompt.prompt_data) # ✓ correct content
print(prompt.version_id) # None ← expected: e.g. "3"
print(prompt.version_name) # None ← expected: e.g. "abc123"
```

### Pinned fetch works correctly

```
prompt_pinned = prompts.get(prompt_id="123456789", version_id="3")
print(prompt_pinned.version_id) # "3" ✓
print(prompt_pinned.version_name) # "abc123" ✓
```

### Stack trace

No exception is raised. The fields are silently None.

### Root cause

In vertexai/prompts/_prompt_management.py, get() unconditionally assigns the caller-supplied argument back to the object:

prompt._version_id = version_id # always None when no version_id passed
### _version_name is never set on this path

The underlying _get_prompt_resource() calls GetDataset, whose response carries no version pointer. _version_name is never set anywhere in the latest-fetch
path.

Compare with _get_prompt_resource_from_version(), which correctly calls get_dataset_version() and sets both fields.

Related: #6193 describes the symmetric bug — get_version() returns the wrong content for a pinned version.

### Workaround

```
raw = prompts.get(prompt_id=prompt_id)
versions = prompts.list_versions(prompt_id=prompt_id)
if versions:
latest = max(versions, key=lambda v: int(v.version_id))
raw._version_id = latest.version_id
raw._version_name = latest.display_name
```

Works but costs an extra paginated ListDatasetVersions call per fetch.

### Possible fix

In _get_prompt_resource(), after get_dataset, issue a list_dataset_versions with page_size=1 to get the latest version metadata:

```

versions = prompt._dataset_client.list_dataset_versions(parent=name, page_size=1)
for version in versions:
prompt._version_id = version.name.split("/")[-1]
prompt._version_name = version.display_name
break
```

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Hướng nghiên cứu

Bắt đầu trong vertexai/prompts/_prompt_management.py, đặc biệt là get(), _get_prompt_resource() và _get_prompt_resource_from_version(); so sánh cách các lần fetch phiên bản mới nhất và phiên bản được ghim điền metadata phiên bản. Tái hiện trường hợp prompts.get() không ghim phiên bản và xác minh rằng version_id và version_name được điền cho phiên bản mới nhất, đồng thời hành vi fetch phiên bản được ghim vẫn đúng.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Đánh giá

Công nghệ
python
Lĩnh vực
api, machine-learning
Loại issue
Lỗi
Độ khó
3/5
Thời gian dự kiến
1-2 ngày
Mức độ hoạt động
Ít trao đổi
Độ rõ ràng
Đặc tả rõ ràng
Mức phù hợp với người mới
72/100

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.