googleapis / googleapis/python-aiplatform

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

Open
#6,637 0 comments 0 reactions 0 assignees View on GitHub
api: vertex-ai
Dominant language
Python
Stars
905
Forks
465
Avg merge
1d 13h
Merged PRs (30d)
44

Description

### 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
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.