googleapis / googleapis/python-aiplatform
vertexai.preview.prompts.get() does not populate version_id or version_name when fetching latest version
还没有人认领这个 Issue。
- 主要语言
- Python
- 星标
- 907
- 派生
- 466
- 平均合并
- 1 天 13 小时
- 30 天内合并 PR
- 44
描述
### 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
```
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
从 vertexai/prompts/_prompt_management.py 开始,重点查看 get()、_get_prompt_resource() 和 _get_prompt_resource_from_version();比较获取最新版本和固定版本时如何填充版本元数据。复现未指定版本的 prompts.get() 情况,并验证最新版本的 version_id 和 version_name 已填充,同时固定版本的获取行为保持正确。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- python
- 领域
- api, machine-learning
- Issue 类型
- 缺陷
- 难度
- 3/5
- 预计耗时
- 1-2 天
- 活跃度
- 冷清
- 描述清晰度
- 描述清楚
- 新手友好度
- 72/100