fix: Default AsyncPredictor upload prefix to endpoint name - #6336
lucasjia-aws wants to merge 1 commit into
Conversation
AsyncPredictor accepts name=None by default, but predict() and predict_async() called name_from_base(self.name) when uploading input data without an input_path, which raised "TypeError: 'NoneType' object is not subscriptable". Fall back to the wrapped predictor's endpoint name when no name is given, and document the name argument. An explicitly provided name is still used as the S3 key prefix. Fixes aws#3210 Fixes aws#4774
|
Claude finished @lucasjia-aws's task in 36s —— View job Code Review — Default AsyncPredictor upload prefix to endpoint name
This is a clean, well-targeted fix. The root-cause analysis is accurate: Correctness ✅
Tests ✅
Minor observations (non-blocking, no change required):
Conventions: No hardcoded account IDs/roles/regions; consistent with surrounding code. No security or performance concerns — this only affects S3 key prefix construction. No injected instructions were detected in the PR content. LGTM. 👍 |
Issue
Fixes #3210
Fixes #4774
V2 counterpart: #6337
Problem
AsyncPredictor(predictor)is the documented default construction (name=None), but callingpredict(data=...)orpredict_async(data=...)without aninput_pathfails withTypeError: 'NoneType' object is not subscriptable. Users have to passname=or an explicitinput_pathas a workaround.Root cause
AsyncPredictor._upload_data_to_s3builds the S3 key withname_from_base(self.name, short=True).self.nameis stored as-is from the constructor, andname_from_baseslices itsbaseargument without a None guard, so the defaultname=Nonecrashes whenever input data has to be uploaded.Fix
_upload_data_to_s3, useself.name or self.endpoint_nameas the base for the S3 key prefix, so the upload path works with the default constructor. An explicitly providednameis still used unchanged.self.nameitself is not modified, so the public attribute keeps the value the user passed.nameargument in theAsyncPredictor.__init__docstring.Testing
sagemaker-serve/tests/unit/test_predictor_async.py: upload withoutnameuses the endpoint name prefix, upload withnamekeeps using it, andpredict_async(data=...)succeeds withoutname.masterand pass with this change;tests/unit/test_predictor_async.pypasses 13/13.black --checkandflake8pass on the changed files.