Skip to content

fix: flatten the pages in DeploymentResourcePool.query_deployed_models - #7231

Open
abhishekacharya200 wants to merge 1 commit into
googleapis:mainfrom
abhishekacharya200:fix/drp-query-deployed-models-flatten
Open

abhishekacharya200 wants to merge 1 commit into
googleapis:mainfrom
abhishekacharya200:fix/drp-query-deployed-models-flatten

Conversation

@abhishekacharya200

Copy link
Copy Markdown

Fixes #7230 🦕

DeploymentResourcePool.query_deployed_models() is documented, and annotated, to return a list of DeployedModelRef objects, but it built that list with itertools.chain(page.deployed_model_refs for page in response.pages). Passing a single generator to chain does not flatten it, so the result held one RepeatedComposite per page instead of the refs themselves. With one page holding two refs the method returned a list of length 1, and refs[0].deployed_model_id raised AttributeError.

This switches to itertools.chain.from_iterable(...) in both the GA class (google/cloud/aiplatform/models.py) and the preview class (google/cloud/aiplatform/preview/models.py), so the method returns what its docstring and return type promise.

Tests in tests/unit/aiplatform/test_deployment_resource_pools.py:

  • test_query_deployed_models now checks the returned deployed_model_id values, not only the length. The length check passed with the bug because the fixture has two pages with one ref each.
  • test_query_deployed_models_with_several_refs_in_one_page covers one page holding two refs.
  • test_preview_query_deployed_models covers the preview class.

All three fail on main and pass with this change, and the whole file passes (12 passed). black==24.8.0 and flake8==6.1.0 from the noxfile report nothing on the changed files.

With the script from #7230:

main (faed3f4)
len: 1 | item types: ['RepeatedComposite']
refs[0].deployed_model_id -> AttributeError: 'RepeatedComposite' object has no attribute 'deployed_model_id'

this branch
len: 2 | item types: ['DeployedModelRef', 'DeployedModelRef']
first deployed_model_id: m1

itertools.chain was called with a single generator, so it did not
flatten anything: the method returned one RepeatedComposite per page
instead of the documented list of DeployedModelRef objects. Use
itertools.chain.from_iterable in both the GA and preview classes.
@abhishekacharya200
abhishekacharya200 requested a review from a team as a code owner October 20, 2026 04:02
@product-auto-label product-auto-label Bot added size: m Pull request size is medium. api: vertex-ai Issues related to the googleapis/python-aiplatform API. labels Oct 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

api: vertex-ai Issues related to the googleapis/python-aiplatform API. size: m Pull request size is medium.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

DeploymentResourcePool.query_deployed_models returns page containers instead of DeployedModelRef objects

1 participant