Skip to content

Commit 3473997

Browse files
committed
fix: handle trial component status message longer than API supports
1 parent fd566bd commit 3473997

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

src/sagemaker/experiments/run.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@
6868
TRIAL_NAME_TEMPLATE = "Default-Run-Group-{}"
6969
MAX_RUN_TC_ARTIFACTS_LEN = 30
7070
MAX_NAME_LEN_IN_BACKEND = 120
71+
MAX_STATUS_MESSAGE_LEN = 1024
7172
EXPERIMENT_NAME = "ExperimentName"
7273
TRIAL_NAME = "TrialName"
7374
RUN_NAME = "RunName"
@@ -759,7 +760,7 @@ def __exit__(self, exc_type, exc_value, exc_traceback):
759760
if exc_value:
760761
self._trial_component.status = _api_types.TrialComponentStatus(
761762
primary_status=_TrialComponentStatusType.Failed.value,
762-
message=str(exc_value),
763+
message=(str(exc_value) or '')[:MAX_STATUS_MESSAGE_LEN]
763764
)
764765
else:
765766
self._trial_component.status = _api_types.TrialComponentStatus(

tests/unit/sagemaker/experiments/test_run.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1077,6 +1077,20 @@ def test_exit_fail(sagemaker_session, run_obj):
10771077
assert run_obj._trial_component.status.message
10781078
assert isinstance(run_obj._trial_component.end_time, datetime.datetime)
10791079

1080+
def test_exit_fail_message_too_long(sagemaker_session, run_obj):
1081+
sagemaker_session.sagemaker_client.update_trial_component.return_value = {}
1082+
# create an error message that is longer than the max status message length of 1024
1083+
# 3 x 342 = 1026
1084+
too_long_error_message = "Foo" * 342
1085+
try:
1086+
with run_obj:
1087+
raise ValueError("Foo")
1088+
except ValueError:
1089+
pass
1090+
1091+
assert run_obj._trial_component.status.primary_status == _TrialComponentStatusType.Failed.value
1092+
assert run_obj._trial_component.status.message == too_long_error_message[:1024]
1093+
assert isinstance(run_obj._trial_component.end_time, datetime.datetime)
10801094

10811095
@pytest.mark.parametrize(
10821096
"metric_value",

0 commit comments

Comments
 (0)