@@ -182,7 +182,13 @@ class TestModelTrainerPipelineVariableHyperparameters:
182182 """Test that PipelineVariable objects work correctly in ModelTrainer hyperparameters."""
183183
184184 def test_hyperparameters_with_parameter_integer (self ):
185- """ParameterInteger in hyperparameters should be preserved through _create_training_job_args."""
185+ """ParameterInteger in hyperparameters should be preserved through _create_training_job_args.
186+
187+ This test documents the exact bug scenario from GH#5504: safe_serialize
188+ would fall back to str(data) for PipelineVariable objects, but
189+ PipelineVariable.__str__ intentionally raises TypeError.
190+ Before the fix, this call would have raised TypeError.
191+ """
186192 max_depth = ParameterInteger (name = "MaxDepth" , default_value = 5 )
187193 trainer = ModelTrainer (
188194 training_image = DEFAULT_IMAGE ,
@@ -192,6 +198,7 @@ def test_hyperparameters_with_parameter_integer(self):
192198 output_data_config = DEFAULT_OUTPUT ,
193199 hyperparameters = {"max_depth" : max_depth },
194200 )
201+ # This call would have raised TypeError before the fix (GH#5504)
195202 args = trainer ._create_training_job_args ()
196203 # PipelineVariable should be preserved as-is, not stringified
197204 assert args ["hyper_parameters" ]["max_depth" ] is max_depth
@@ -210,32 +217,6 @@ def test_hyperparameters_with_parameter_string(self):
210217 args = trainer ._create_training_job_args ()
211218 assert args ["hyper_parameters" ]["algorithm" ] is algo
212219
213- def test_hyperparameters_with_parameter_integer_does_not_raise (self ):
214- """Verify ParameterInteger in hyperparameters does NOT raise TypeError.
215-
216- This test documents the exact bug scenario from GH#5504: safe_serialize
217- would fall back to str(data) for PipelineVariable objects, but
218- PipelineVariable.__str__ intentionally raises TypeError.
219- """
220- max_depth = ParameterInteger (name = "MaxDepth" , default_value = 5 )
221- trainer = ModelTrainer (
222- training_image = DEFAULT_IMAGE ,
223- role = DEFAULT_ROLE ,
224- compute = DEFAULT_COMPUTE ,
225- stopping_condition = DEFAULT_STOPPING ,
226- output_data_config = DEFAULT_OUTPUT ,
227- hyperparameters = {"max_depth" : max_depth },
228- )
229- # This call would have raised TypeError before the fix
230- try :
231- args = trainer ._create_training_job_args ()
232- except TypeError :
233- pytest .fail (
234- "safe_serialize raised TypeError on PipelineVariable - "
235- "this is the bug described in GH#5504"
236- )
237- assert args ["hyper_parameters" ]["max_depth" ] is max_depth
238-
239220 def test_hyperparameters_with_mixed_pipeline_and_static_values (self ):
240221 """Mixed PipelineVariable and static values should both be handled correctly."""
241222 max_depth = ParameterInteger (name = "MaxDepth" , default_value = 5 )
0 commit comments