Skip to content

fix: pass the configured session to Model.get in ModelBuilder.build - #6470

Closed
WeAreResilience wants to merge 1 commit into
aws:masterfrom
WeAreResilience:fix/6459-model-get-session
Closed

WeAreResilience wants to merge 1 commit into
aws:masterfrom
WeAreResilience:fix/6459-model-get-session

Conversation

@WeAreResilience

Copy link
Copy Markdown

Issue #, if available: #6459

Description of changes:

_create_sagemaker_model creates the model through self.sagemaker_session, then reloads it with Model.get(model_name=..., region=...). With no session, the describe goes through the default boto session, so if that session points at a different account the call fails because the model only exists in the target account.

The fix passes session=self.sagemaker_session.boto_session to Model.get, the same way Transformer already does in sagemaker-core. The PipelineSession early return is unchanged.

Added tests/unit/test_model_builder_model_get_session.py, which checks that Model.get receives the configured boto session. It fails on master and passes with the fix.

Testing: in sagemaker-serve, tox -e flake8,black-check,docstyle,pylint passes, and so does the new test. The full tests/unit run gave 2076 passed and 65 failed, and the same 65 tests also fail on master in my environment, so the fix doesn't add any failures. I didn't reproduce this against two real AWS accounts.

_get_model_from_endpoint and _find_reusable_model call Model.get without the session as well. I kept them out of this change to stay within the issue, but I can follow up on them if you'd like.

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

ModelBuilder created the model with self.sagemaker_session but reloaded
it with Model.get() using only the region, so the describe call went
through the default boto session. When that session points at a
different account, the describe fails because the model does not exist
there.

Fixes #6459
@WeAreResilience

Copy link
Copy Markdown
Author

Thanks @mohamedzeidan2021, #6487 covers this and also handles the other Model reloads, so I'm closing this one in favor of it. Glad to see #6459 fixed.

This branch is waiting to be deployed

1 waiting deployment
manual-approval — 98fa1a3b Waiting Oct 14, 2026 by WeAreResilience via wait-for-approval #1756
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant