Skip to content

fix: handle clients without _user_agent_creator in ModelBuilder.build - #6604

Open
themanoj-025 wants to merge 1 commit into
aws:masterfrom
themanoj-025:fix-modelbuilder-localsession-user-agent
Open

themanoj-025 wants to merge 1 commit into
aws:masterfrom
themanoj-025:fix-modelbuilder-localsession-user-agent

Conversation

@themanoj-025

Copy link
Copy Markdown

Description of changes

In \ModelBuilder._build_single_modelbuilder, \�uild()\ unconditionally attempted to decorate \client._user_agent_creator.to_string:
\\python
client = self.sagemaker_session.sagemaker_client
client._user_agent_creator.to_string = self._user_agent_decorator(
self.sagemaker_session.sagemaker_client._user_agent_creator.to_string
)
\
When \LocalSession\ is used (e.g. local container or local mode workflow), \sagemaker_client\ is a \LocalSagemakerClient\ (or custom non-botocore client) which does not have a _user_agent_creator\ attribute. This causes:
\
AttributeError: 'LocalSagemakerClient' object has no attribute '_user_agent_creator'
\\

This PR safely checks for _user_agent_creator\ using \getattr(client, '_user_agent_creator', None). If present (as in standard botocore clients), the user agent decorator is applied as expected; if absent (as in \LocalSagemakerClient), the build proceeds cleanly without error.

Fixes #6603

Tests

  • Added \ est_build_single_without_user_agent_creator\ in \sagemaker-serve/tests/unit/test_model_builder_v3.py\ verifying that _build_single_modelbuilder\ succeeds without error when _user_agent_creator\ is not present.
  • Added \ est_build_single_decorates_user_agent_when_creator_present\ in \sagemaker-serve/tests/unit/test_model_builder_v3.py\ verifying that _user_agent_creator.to_string\ is decorated with \ModelBuilder\ when present.
  • Passed all unit tests via pytest and verified style compliance with Black.

Documentation

No documentation changes required.

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

This branch is waiting to be deployed

1 waiting deployment
manual-approval — 1fb69937 Waiting Nov 27, 2026 by themanoj-025 via wait-for-approval #2280
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.

ModelBuilder.build fails with LocalSession because LocalSagemakerClient has no _user_agent_creator

1 participant