fix(serve): Support pipeline variable image_uri in ModelBuilder.build - #6347
Open
lucasjia-aws wants to merge 1 commit into
Open
lucasjia-aws wants to merge 1 commit into
lucasjia-aws wants to merge 1 commit into
Conversation
ModelBuilder.image_uri is typed Optional[StrPipeVar], but build() treated it as a plain string in two places, so a ParameterString image failed under a PipelineSession: - is_1p_image_uri() sliced the value (image_uri[0:12]), raising "'ParameterString' object is not subscriptable" in _build_validations. - _create_sagemaker_model() ran "nova-" in image_uri for the Nova network-isolation default, raising "argument of type 'ParameterString' is not iterable". A pipeline variable is only resolved at execution time, so is_1p_image_uri() now treats non-string values as not first-party, and the Nova network-isolation check only inspects string images. The pipeline variable is passed through unchanged to CreateModel. Fixes aws#5760
|
Claude finished @lucasjia-aws's task in 1m 22s —— View job ReviewI reviewed the diff against (Note: the inline-comment tool isn't available in this run, so findings are consolidated here with file/line references.) Correctness ✅
Types
Tests ✅
Minor observations (non-blocking)
No security or performance concerns; the change removes failure modes rather than adding surface area, and adheres to the repo's v3-by-default guidance (all examples/tests use |
This branch was successfully deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Issue
Fixes #5760. Supersedes #5910.
Problem
ModelBuilder.build()fails whenimage_uriis a pipeline variable such asParameterStringunder aPipelineSession, even thoughModelBuilder.image_uriis typedOptional[StrPipeVar]. This blocks V2 -> V3 pipeline migrations that parameterize the serving image.Root cause
The build path treats
image_urias a plain string in two places. First,_build_validationscallsis_1p_image_uri(self.image_uri), which slices the value withimage_uri[0:12]and raisesTypeError: 'ParameterString' object is not subscriptable(the error in the issue). Second, once that is fixed,_create_sagemaker_modelevaluates"nova-" in resolved_image_urifor the Nova network-isolation default and raisesTypeError: argument of type 'ParameterString' is not iterable.PipelineVariableintentionally defines neither__getitem__nor__contains__, and its__str__raises.#5910 only addresses the first failure, so the reporter's snippet still fails with it applied.
Fix
is_1p_image_urireturnsFalsefor any non-string value. A pipeline variable is only resolved at execution time, so its account cannot be inspected at build time. On the image-only passthrough path both branches of_build_validationslead to passthrough, so the result is unchanged; with amodeland nomodel_server, users now get the existing "Model_server must be set" error instead of aTypeError._create_sagemaker_modelonly inspects string images. For a pipeline-variable image, setenable_network_isolationexplicitly if needed."Image": {"Get": "Parameters.<name>"}.Testing
tests/unit/test_model_builder_pipeline_variable_image_uri.py:_build_validationspassthrough and model_server cases, the_create_sagemaker_modelnetwork-isolation check with a pipeline-variable image and a Nova 1P string image (regression guard), and an end-to-endbuild()under a realPipelineSessionasserting theCreateModelrequest keeps theParameterString.tests/unit/validations/test_check_image_uri.py:ParameterString(with a 1P default value),Join, andNoneinputs.sagemaker-serveunit test failure set is identical before and after the change.ModelStepbuilt from the result produces a pipeline definition with the parameterized image.