aws / aws/sagemaker-python-sdk
ModelPackage.get_all() fails with ParamValidationError for versioned packages in a model package group
- Dominant language
- Python
- Stars
- 2.3k
- Forks
- 1.3k
- Avg merge
- 1d 22h
- Merged PRs (30d)
- 35
Description
**PySDK Version**
- [ ] PySDK V2 (2.x)
- [x] PySDK V3 (3.x)
**Describe the bug**
`ModelPackage.get_all()` fails with `ParamValidationError: Missing required parameter in input: "ModelPackageName"` when listing versioned model packages within a model package group. The `ResourceIterator` calls `refresh()` on each `ModelPackage` object it constructs from the list summary. The `refresh()` method uses `self.model_package_name` to call `DescribeModelPackage`, but for versioned model packages the `ListModelPackages` API does not return `ModelPackageName`; it only returns `ModelPackageArn`. Since `model_package_name` remains `Unassigned`, it gets serialized to `None` and dropped from the request, causing the missing parameter error.
**To reproduce**
Prerequisites: An existing model package group with at least one versioned model package.
```python
from sagemaker.core.resources import ModelPackage
# This will fail on the first iteration when refresh() is called
for pkg in ModelPackage.get_all(
model_package_group_name="",
sort_by="CreationTime",
sort_order="Descending",
):
print(pkg.model_package_arn)
```
**Expected behavior**
ModelPackage.get_all() should successfully iterate over all model packages in the group. The refresh() method should
fall back to using model_package_arn when model_package_name is not available, since DescribeModelPackage accepts either a name or an ARN for the ModelPackageName parameter.
**Screenshots or logs**
```
ParamValidationError: Parameter validation failed: Missing required parameter in input: "ModelPackageName"
File "sagemaker/core/utils/utils.py", line 469, in __next__
resource_object.refresh()
File "sagemaker/core/resources.py", line 25130, in refresh
response = client.describe_model_package(**operation_input_args)
```
**System information**
A description of your system. Please provide:
- **SageMaker Python SDK version**: 3.5
- **Framework name (eg. PyTorch) or algorithm (eg. KMeans)**: N/A
- **Framework version**: N/A
- **Python version**: 3.12
- **CPU or GPU**: CPU
- **Custom Docker image (Y/N)**: N
**Additional context**
N/A
Contributor guide
Assessment
This issue has not been assessed yet.