diff --git a/sdk/python/kfp/compiler/compiler.py b/sdk/python/kfp/compiler/compiler.py index e93afd6aa0a..ab78f63a9c1 100644 --- a/sdk/python/kfp/compiler/compiler.py +++ b/sdk/python/kfp/compiler/compiler.py @@ -508,7 +508,7 @@ def _convert_k8s_obj_to_dic(self, obj): Returns: The serialized form of data. """ - from six import text_type, integer_types + from six import text_type, integer_types, iteritems PRIMITIVE_TYPES = (float, bool, bytes, text_type) + integer_types from datetime import date, datetime if obj is None: @@ -532,7 +532,6 @@ def _convert_k8s_obj_to_dic(self, obj): # and attributes which value is not None. # Convert attribute name to json key in # model definition for request. - from six import iteritems obj_dict = {obj.attribute_map[attr]: getattr(obj, attr) for attr, _ in iteritems(obj.swagger_types) if getattr(obj, attr) is not None} diff --git a/sdk/python/tests/compiler/compiler_tests.py b/sdk/python/tests/compiler/compiler_tests.py index 4c0c9c6a7c1..6363d6537a9 100644 --- a/sdk/python/tests/compiler/compiler_tests.py +++ b/sdk/python/tests/compiler/compiler_tests.py @@ -23,6 +23,7 @@ import tempfile import unittest import yaml +import datetime class TestCompiler(unittest.TestCase): @@ -141,6 +142,21 @@ def test_basic_workflow(self): shutil.rmtree(tmpdir) # print(tmpdir) + def test_convert_k8s_obj_to_dic_accepts_dict(self): + now = datetime.datetime.now() + converted = compiler.Compiler()._convert_k8s_obj_to_dic({ + "ENV": "test", + "number": 3, + "list": [1,2,3], + "time": now + }) + self.assertEqual(converted, { + "ENV": "test", + "number": 3, + "list": [1,2,3], + "time": now.isoformat() + }) + def test_composing_workflow(self): """Test compiling a simple workflow, and a bigger one composed from the simple one."""