Skip to content

Commit db90567

Browse files
authored
fix(core): Make DataCaptureConfigSummary.kms_key_id optional (#6346)
DescribeEndpoint omits DataCaptureConfig.KmsKeyId when data capture is enabled without a customer-managed KMS key, but the service model marks it as required, so codegen emitted DataCaptureConfigSummary.kms_key_id as a required field. As a result Endpoint.get() raised a pydantic ValidationError for any endpoint with data capture enabled and no KMS key. Register the member in REQUIRED_TO_OPTIONAL_OVERRIDES so codegen keeps it optional, and update the generated shape to match. Add unit tests for the codegen override, the shape, and Endpoint.get(). Fixes #5738
1 parent 7d43dcf commit db90567

4 files changed

Lines changed: 116 additions & 2 deletions

File tree

‎sagemaker-core/src/sagemaker/core/shapes/shapes.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10125,7 +10125,7 @@ class DataCaptureConfigSummary(Base):
1012510125
capture_status: StrPipeVar
1012610126
current_sampling_percentage: int
1012710127
destination_s3_uri: StrPipeVar
10128-
kms_key_id: StrPipeVar
10128+
kms_key_id: Optional[StrPipeVar] = Unassigned()
1012910129

1013010130

1013110131
class DebugRuleEvaluationStatus(Base):

‎sagemaker-core/src/sagemaker/core/tools/constants.py‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,9 @@
126126
"ModelPackageSecurityConfig": ["KmsKeyId"],
127127
# S3Uri is optional when ModelDataSource references escrow-managed artifacts (RMP).
128128
"S3ModelDataSource": ["S3Uri"],
129+
# DescribeEndpoint omits DataCaptureConfig.KmsKeyId when data capture is enabled
130+
# without a customer-managed KMS key (S3 default encryption is used instead).
131+
"DataCaptureConfigSummary": ["KmsKeyId"],
129132
}
130133

131134
# Members where the generated primitive type should be replaced with a PipelineVariable

‎sagemaker-core/tests/unit/generated/test_shapes.py‎

Lines changed: 55 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
import ast
2+
import datetime
23
import unittest
4+
from unittest.mock import MagicMock, patch
35

46
from pydantic import BaseModel, ValidationError
57

68
import os
7-
from sagemaker.core.shapes import Base, AdditionalS3DataSource
9+
from sagemaker.core.resources import Base as ResourceBase, Endpoint
10+
from sagemaker.core.shapes import Base, AdditionalS3DataSource, DataCaptureConfigSummary
811
from sagemaker.core.utils.utils import Unassigned
912

1013
# Use the installed package location
@@ -58,3 +61,54 @@ def _fetch_number_of_classes_in_file_not_inheriting_a_class(
5861
if not any(base_class.id == base_class_name for base_class in node.bases):
5962
count = count + 1
6063
return count
64+
65+
66+
class TestDataCaptureConfigSummaryOptionalKmsKeyId(unittest.TestCase):
67+
"""DescribeEndpoint omits DataCaptureConfig.KmsKeyId when data capture is enabled
68+
without a customer-managed KMS key (issue #5738)."""
69+
70+
_DESCRIBE_ENDPOINT_RESPONSE = {
71+
"EndpointName": "my-endpoint",
72+
"EndpointArn": "arn:aws:sagemaker:us-west-2:111122223333:endpoint/my-endpoint",
73+
"EndpointConfigName": "my-endpoint-config",
74+
"EndpointStatus": "InService",
75+
"CreationTime": datetime.datetime(2026, 1, 1),
76+
"LastModifiedTime": datetime.datetime(2026, 1, 1),
77+
"DataCaptureConfig": {
78+
"EnableCapture": True,
79+
"CaptureStatus": "Started",
80+
"CurrentSamplingPercentage": 100,
81+
"DestinationS3Uri": "s3://my-bucket/data-capture",
82+
},
83+
}
84+
85+
def test_shape_validates_without_kms_key_id(self):
86+
summary = DataCaptureConfigSummary(
87+
enable_capture=True,
88+
capture_status="Started",
89+
current_sampling_percentage=100,
90+
destination_s3_uri="s3://my-bucket/data-capture",
91+
)
92+
assert isinstance(summary.kms_key_id, Unassigned)
93+
94+
def test_shape_accepts_kms_key_id(self):
95+
summary = DataCaptureConfigSummary(
96+
enable_capture=True,
97+
capture_status="Started",
98+
current_sampling_percentage=100,
99+
destination_s3_uri="s3://my-bucket/data-capture",
100+
kms_key_id="my-kms-key",
101+
)
102+
assert summary.kms_key_id == "my-kms-key"
103+
104+
def test_endpoint_get_without_kms_key_id(self):
105+
client = MagicMock()
106+
client.describe_endpoint.return_value = self._DESCRIBE_ENDPOINT_RESPONSE
107+
# Endpoint.get() resolves its client via resources.Base.get_sagemaker_client.
108+
with patch.object(ResourceBase, "get_sagemaker_client", return_value=client):
109+
endpoint = Endpoint.get("my-endpoint")
110+
111+
client.describe_endpoint.assert_called_once_with(EndpointName="my-endpoint")
112+
assert endpoint.data_capture_config.enable_capture is True
113+
assert endpoint.data_capture_config.destination_s3_uri == "s3://my-bucket/data-capture"
114+
assert isinstance(endpoint.data_capture_config.kms_key_id, Unassigned)

‎sagemaker-core/tests/unit/tools/test_shapes_extractor.py‎

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -435,3 +435,60 @@ def test_override_is_targeted_not_blanket(self, extractor):
435435
members = extractor.generate_shape_members("UnrelatedConfig")
436436
assert "IntPipeVar" not in members["instance_count"]
437437
assert "int" in members["instance_count"]
438+
439+
440+
class TestDataCaptureConfigSummaryRequiredToOptionalOverride:
441+
"""The service model marks DataCaptureConfigSummary.KmsKeyId as required, but
442+
DescribeEndpoint omits it when data capture has no customer-managed KMS key
443+
(issue #5738). REQUIRED_TO_OPTIONAL_OVERRIDES must keep codegen emitting it as
444+
Optional, otherwise Endpoint.get() fails validation on such endpoints."""
445+
446+
_STRING = {"type": "string"}
447+
_MODEL = {
448+
"EnableCapture": {"type": "boolean"},
449+
"CaptureStatus": _STRING,
450+
"SamplingPercentage": {"type": "integer"},
451+
"DestinationS3Uri": _STRING,
452+
"KmsKeyId": _STRING,
453+
"DataCaptureConfigSummary": {
454+
"type": "structure",
455+
"required": [
456+
"EnableCapture",
457+
"CaptureStatus",
458+
"CurrentSamplingPercentage",
459+
"DestinationS3Uri",
460+
"KmsKeyId",
461+
],
462+
"members": {
463+
"EnableCapture": {"shape": "EnableCapture"},
464+
"CaptureStatus": {"shape": "CaptureStatus"},
465+
"CurrentSamplingPercentage": {"shape": "SamplingPercentage"},
466+
"DestinationS3Uri": {"shape": "DestinationS3Uri"},
467+
"KmsKeyId": {"shape": "KmsKeyId"},
468+
},
469+
},
470+
}
471+
472+
@pytest.fixture
473+
def extractor(self, tmp_path):
474+
# Constructing the extractor regenerates shape_dag.py; point that write
475+
# at a temp file so the unit test leaves the checked-in file alone.
476+
with (
477+
patch("sagemaker.core.tools.shapes_extractor.reformat_file_with_black"),
478+
patch(
479+
"sagemaker.core.tools.shapes_extractor.SHAPE_DAG_FILE_PATH",
480+
str(tmp_path / "shape_dag.py"),
481+
),
482+
):
483+
return ShapesExtractor(combined_shapes=self._MODEL)
484+
485+
def test_kms_key_id_generated_as_optional(self, extractor):
486+
members = extractor.generate_shape_members("DataCaptureConfigSummary")
487+
assert members["kms_key_id"] == "Optional[StrPipeVar] = Unassigned()"
488+
489+
def test_other_members_stay_required(self, extractor):
490+
members = extractor.generate_shape_members("DataCaptureConfigSummary")
491+
assert members["enable_capture"] == "bool"
492+
assert members["capture_status"] == "StrPipeVar"
493+
assert members["current_sampling_percentage"] == "int"
494+
assert members["destination_s3_uri"] == "StrPipeVar"

0 commit comments

Comments
 (0)