Skip to content

fix: validate python version in get_base_python_image_uri - #6547

Open
Fire162 wants to merge 1 commit into
aws:masterfrom
Fire162:fix/base-python-image-uri-validation
Open

Fire162 wants to merge 1 commit into
aws:masterfrom
Fire162:fix/base-python-image-uri-validation

Conversation

@Fire162

@Fire162 Fire162 commented Oct 29, 2026

Copy link
Copy Markdown

Issue #, if available

Fixes #6539

Description

get_base_python_image_uri previously accepted any string for py_version without validation. For Python versions without base images in ECR (such as 311 or 313), it returned image URIs that failed downstream during job creation when pulling from ECR.

Fix

  • Added "py_versions": ["310", "38"] to versions["1.0"] in sagemaker-core/src/sagemaker/core/image_uri_config/sagemaker-base-python.json.
  • Added validation in get_base_python_image_uri via _validate_py_version_and_set_if_needed, matching how framework image URIs validate python versions across the SDK.
  • Updated docstring to document the ValueError raised on unsupported versions.
  • Added unit test coverage in sagemaker-core/tests/unit/image_uris/test_base_python.py for unsupported python versions.

Testing done

  • Ran pytest sagemaker-core/tests/unit/image_uris/test_base_python.py -> 7 passed.
  • Verified valid versions (310, 38) resolve expected URIs across all regions.
  • Verified invalid/unsupported versions (311, 312, 313, 39, invalid) raise ValueError: Unsupported Python version.

Merge Checklist

  • I have read the CONTRIBUTING doc
  • I used the commit message format described in CONTRIBUTING
  • I have passed the region in to all S3 and STS clients that I've initialized as part of this change (N/A)
  • I have updated any necessary documentation, including READMEs and API docs (if appropriate)

Tests

  • I have added tests that prove my fix is effective or that my feature works (if appropriate)
  • I have added unit and/or integration tests as appropriate to ensure backward compatibility of the changes

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

get_base_python_image_uri previously accepted any string for py_version
without validation, returning image URIs for non-existent base images in
ECR (such as 311 or 313) that failed downstream at job execution.

Add py_versions configuration to sagemaker-base-python.json (310, 38)
and validate py_version via _validate_py_version_and_set_if_needed,
raising a clear ValueError when an unsupported version is requested.
Also add unit test coverage for invalid python versions.

Fixes aws#6539

This branch is waiting to be deployed

1 waiting deployment
manual-approval — 3c1038fd Waiting Oct 29, 2026 by Fire162 via wait-for-approval #774
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.

get_base_python_image_uri() returns URIs for unsupported Python versions

1 participant