Skip to content

fix: Fix cross account register model #3726

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/sagemaker/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -3222,7 +3222,9 @@ def create_model_package_from_containers(
)

def submit(request):
if model_package_group_name is not None:
if model_package_group_name is not None and not model_package_group_name.startswith(
"arn:"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is the startswitharn check enough? to cover all such cases?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, this check would be sufficient. confirmed with madbal@

):
_create_resource(
lambda: self.sagemaker_client.create_model_package_group(
ModelPackageGroupName=request["ModelPackageGroupName"]
Expand Down
29 changes: 29 additions & 0 deletions tests/unit/test_session.py
Original file line number Diff line number Diff line change
Expand Up @@ -2650,6 +2650,35 @@ def test_create_model_package_from_containers(sagemaker_session):
sagemaker_session.sagemaker_client.create_model_package.assert_called_once()


def test_create_model_package_from_containers_cross_account_mpg_name(sagemaker_session):
mpg_name = "arn:aws:sagemaker:us-east-1:215995503607:model-package-group/stage-dev"
content_types = ["text/csv"]
response_types = ["text/csv"]
sagemaker_session.create_model_package_from_containers(
model_package_group_name=mpg_name,
content_types=content_types,
response_types=response_types,
)
sagemaker_session.sagemaker_client.create_model_package.assert_called_once()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you also assert that create_model_package_group wasn't called for this case?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

addressed in revision 2



def test_create_mpg_from_containers_cross_account_mpg_name(sagemaker_session):
mpg_name = "arn:aws:sagemaker:us-east-1:215995503607:model-package-group/stage-dev"
content_types = ["text/csv"]
response_types = ["text/csv"]
with pytest.raises(AssertionError) as error:
sagemaker_session.create_model_package_from_containers(
model_package_group_name=mpg_name,
content_types=content_types,
response_types=response_types,
)
sagemaker_session.sagemaker_client.create_model_package_group.assert_called_once()
assert (
"Expected 'create_model_package_group' to have been called once. "
"Called 0 times." == str(error)
)


def test_create_model_package_from_containers_name_conflict(sagemaker_session):
model_package_name = "sagemaker-model-package"
model_package_group_name = "sagemaker-model-package-group"
Expand Down