Repository: caikit/caikit
Pull request #518 (2023-10-10 18:56:18)

🐛 check protoable for list dm type
<!--  Thanks for sending a pull request!  Here are some tips for you:
1. Make sure to read the Contributing Guide before submitting your PR: https://github.com/caikit/caikit/blob/main/CONTRIBUTING.md
2. If this PR closes another issue, add 'closes #<issue number>' somewhere in the PR summary. GitHub will automatically close that issue when this PR gets merged. Alternatively, adding 'refs #<issue number>' will not close the issue, but help provide the reviewer more context.-->

**What this PR does / why we need it**:

Currently we don't support a list of objects in method signatures. I'm not sure if this was intentional?

fix https://github.com/caikit/caikit/issues/519

**Special notes for your reviewer**:

**If applicable**:
- [ ] this PR contains documentation
- [x] this PR contains unit tests
- [ ] this PR has been tested for backwards compatibility



Patch:
diff --git a/caikit/runtime/service_generation/protoable.py b/caikit/runtime/service_generation/protoable.py
index 2ce842c6..ad5f4423 100644
--- a/caikit/runtime/service_generation/protoable.py
+++ b/caikit/runtime/service_generation/protoable.py
@@ -183,7 +183,7 @@ def is_protoable_type(arg_type: Type) -> bool:
             log.debug2("List annotation has no type")
             protoable = False
         else:
-            protoable = typing.get_args(arg_type)[0] in proto_primitive_set
+            protoable = is_protoable_type(typing.get_args(arg_type)[0])
     elif typing.get_origin(arg_type) == dict:
         log.debug2("Arg is Dict")
         if len(typing.get_args(arg_type)) == 0:


Test patch:
diff --git a/tests/runtime/service_generation/test_protoable.py b/tests/runtime/service_generation/test_protoable.py
index 8a70d089..422d14e4 100644
--- a/tests/runtime/service_generation/test_protoable.py
+++ b/tests/runtime/service_generation/test_protoable.py
@@ -52,6 +52,12 @@ def test_to_protoable_signature_dm():
     ) == {"name": SampleInputType}
 
 
+def test_to_protoable_signature_list_dm():
+    assert to_protoable_signature(
+        signature={"name": List[SampleInputType]},
+    ) == {"name": List[SampleInputType]}
+
+
 def test_to_protoable_signature_union_dm():
     assert to_protoable_signature(
         signature={"name": Union[SampleInputType, str]},
diff --git a/tests/runtime/service_generation/test_rpcs.py b/tests/runtime/service_generation/test_rpcs.py
index fc0ce676..15ff35ed 100644
--- a/tests/runtime/service_generation/test_rpcs.py
+++ b/tests/runtime/service_generation/test_rpcs.py
@@ -15,7 +15,7 @@
 """Tests for the rpc objects that hold our in-memory representation of
 what an RPC for a service looks like"""
 # Standard
-from typing import Iterable, Union
+from typing import Iterable, List, Union
 import uuid
 
 # Local
@@ -229,10 +229,40 @@ def test_task_inference_rpc_with_all_optional_params():
 
     data_model = rpc.create_request_data_model(package_name="blah")
     assert data_model is not None
+    assert data_model.fields == ("str_val",)
 
     assert rpc.name == "TestTaskPredict"
 
 
+def test_task_inference_rpc_with_list_of_dm_params():
+    @caikit.core.task(
+        required_parameters={"str_val": str}, output_type=SampleOutputType
+    )
+    class TestTask(TaskBase):
+        pass
+
+    @caikit.core.module(
+        id=str(uuid.uuid4()), name="testest", version="9.9.9", task=TestTask
+    )
+    class TestModule(ModuleBase):
+        def run(
+            self, str_val: str, list_val: List[SampleOutputType]
+        ) -> SampleOutputType:
+            pass
+
+    rpc = TaskPredictRPC(
+        task=TestTask,
+        method_signatures=[TestModule.RUN_SIGNATURE],
+    )
+
+    data_model = rpc.create_request_data_model(package_name="list_dm")
+    assert data_model is not None
+
+    # assert we bring list_val as well
+    assert data_model.fields == ("str_val", "list_val")
+    assert rpc.name == "TestTaskPredict"
+
+
 def test_module_train_rpc():
     @caikit.core.task(
         required_parameters={"str_val": str}, output_type=SampleOutputType