googleapis / googleapis/python-aiplatform
`get_version` returns latest prompt content instead of specified version content
- Dominant language
- Python
- Stars
- 905
- Forks
- 465
- Avg merge
- 1d 13h
- Merged PRs (30d)
- 44
Description
### Description
**Bug Description**
The `get_version` method in `Prompts` class (and `AsyncPrompts`) always returns the latest prompt content regardless of which `version_id` is specified. This is because the method creates the `Prompt` object from `prompt_dataset_resource` (which contains the latest prompt data) instead of `prompt_version_resource` (which contains the version-specific data).
**Steps to Reproduce**
1. Create a prompt with initial content (e.g., "Version 1 content")
2. Create a new version with different content (e.g., "Version 2 content")
3. Repeat step 2 to create multiple versions
4. Call `get_version(prompt_id="...", version_id="1")` to retrieve version 1
5. The returned prompt contains "Version 2 content" (latest) instead of "Version 1 content"
**Expected Behavior**
`get_version` should return the prompt content corresponding to the specified `version_id`.
**Actual Behavior**
`get_version` always returns the latest prompt content, ignoring the `version_id` parameter for the prompt data.
**Root Cause**
In `vertexai/_genai/prompts.py`, the `get_version` method creates the `Prompt` object from `prompt_dataset_resource`:
https://github.com/googleapis/python-aiplatform/blob/47be102c3d27170fe605e9aec69d9d97d9f305ee/vertexai/_genai/prompts.py#L1145-L1175
**Suggested Fix**
The `Prompt` object should be created from `prompt_version_resource` instead:
```python
# Proposed fix
prompt_dataset_resource = self._get_dataset_resource(name=prompt_id)
prompt_version_resource = self._get_dataset_version_resource(
dataset_id=prompt_id,
dataset_version_id=version_id,
)
prompt = _prompt_management_utils._create_prompt_from_dataset_metadata(
prompt_version_resource, # ← Use version-specific resource
)
prompt._dataset = prompt_dataset_resource
prompt._dataset_version = prompt_version_resource
return prompt
```
**Affected Code**
- `Prompts.get_version` (sync version): lines 1145-1175
- `AsyncPrompts.get_version` (async version): lines 2311-2341
**Environment**
- vertexai SDK version: 1.130.0
- Python version: 3.13.2
Contributor guide
Research direction
Start in vertexai/_genai/prompts.py at Prompts.get_version and AsyncPrompts.get_version, using the referenced line ranges and the reproduction steps to compare the dataset and version resources. Done means requesting an older version returns its own prompt content rather than the latest content in both sync and async methods.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- api
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 58/100