Skip to content

fix(serve): let ModelBuilder.register() omit content and response types - #6486

Closed
Thanatos9404 wants to merge 1 commit into
aws:masterfrom
Thanatos9404:fix/register-optional-content-types
Closed

Thanatos9404 wants to merge 1 commit into
aws:masterfrom
Thanatos9404:fix/register-optional-content-types

Conversation

@Thanatos9404

Copy link
Copy Markdown

Issue #, if available: Fixes #6480

Description of changes:

ModelBuilder.register() takes content_types and response_types as optional arguments (default None). It sets self.content_types and self.response_types only when they are passed, but always reads both attributes for get_model_package_args(), so leaving either one out raised AttributeError: 'ModelBuilder' object has no attribute 'content_types' (or 'response_types').

This change defaults both attributes to None in _initialize_defaults(), next to framework and framework_version, which register() reads the same way and which were defaulted there for #5391 (#5424). get_model_package_args() already leaves None values out, so the request has no SupportedContentTypes or SupportedResponseMIMETypes when the types are not given. Both fields are optional in CreateModelPackage (InferenceSpecification requires only Containers). register() itself is unchanged, so types passed to an earlier register() call are still reused by a later call that leaves them out, as the issue asks.

Testing:

  • New sagemaker-serve/tests/unit/test_model_builder_register.py: register() with neither argument, with only content_types, and with only response_types (all 3 fail on master with the AttributeError and pass with this change), plus a check that a second call reuses the types passed to the first.
  • The reproduction from the issue, run offline (PipelineSession with dummy credentials, no AWS calls): on master it raises the AttributeError; with this change the captured CreateModelPackage request has no SupportedContentTypes or SupportedResponseMIMETypes.
  • pytest tests/unit -m "not slow_test" in sagemaker-serve (Python 3.12, run before rebasing onto fix(serve): restore JumpStart default instance type from model spec #6045): no new failures compared with master; the only differences are the 3 new cases, which fail on master. After the rebase, the new tests and TestRegisterReturnsArn give 36 passed.
  • black --check and flake8 pass on the changed files, pydocstyle passes on model_builder.py, and pylint with the repo .pylintrc reports the same messages for model_builder.py before and after the change.

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

register() stores content_types and response_types on the builder only
when they are passed, but always reads self.content_types and
self.response_types when it builds the model package arguments. A call
that leaves either one out (both are optional) raised AttributeError.

Default both attributes to None in _initialize_defaults, next to
framework and framework_version, which register() reads the same way.
get_model_package_args already leaves None values out of the request,
and values passed to an earlier register() call are still reused.

Fixes aws#6480
@Thanatos9404

Copy link
Copy Markdown
Author

Closing this, since #6489 (merged) also fixes #6480: register() now reads content_types and response_types with getattr and has tests for omitting them. Thanks!

This branch is waiting to be deployed

1 waiting deployment
manual-approval — 67d05f6a Waiting Oct 15, 2026 by Thanatos9404 via wait-for-approval #677
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.register() fails when content and response types are omitted

1 participant