Hacktoberfest 2026: the issues maintainers tagged for October, open and beginner-friendly. Browse Hacktoberfest issues

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

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
72/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Quiet
Tech stack
python

Research direction

Start in vertexai/prompts/_prompt_management.py, especially get(), _get_prompt_resource(), and _get_prompt_resource_from_version(); compare how latest and pinned fetches populate version metadata. Reproduce the unpinned prompts.get() case and verify that version_id and version_name are populated for the latest version while pinned fetch behavior remains correct.

Written by the indexing model from the issue text.

Description

api: vertex-ai
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
Dominant language
Python
Stars
907
Forks
467
Avg merge
1d 8h
Merged PRs (30d)
40

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from googleapis/python-aiplatform

All issues in googleapis/python-aiplatform

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.