Skip to content

Commit 9cdcf40

Browse files
author
Heiru Wu
committed
fix(resources): fix nil response handling
1 parent bb052de commit 9cdcf40

File tree

3 files changed

+40
-23
lines changed

3 files changed

+40
-23
lines changed

instill/resources/model.py

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# pylint: disable=no-member,wrong-import-position,no-name-in-module
22
import time
3+
from typing import Optional
34

45
import instill.protogen.model.model.v1alpha.model_definition_pb2 as model_definition_interface
56
import instill.protogen.model.model.v1alpha.model_pb2 as model_interface
@@ -47,12 +48,15 @@ def __init__(
4748

4849
self.resource = model
4950

50-
def __call__(self, task_inputs: list, silent: bool = False) -> list:
51-
return self.client.model_service.trigger_model(
51+
def __call__(self, task_inputs: list, silent: bool = False) -> Optional[list]:
52+
response = self.client.model_service.trigger_model(
5253
self.resource.id,
5354
task_inputs,
5455
silent=silent,
55-
).task_outputs
56+
)
57+
if response is not None:
58+
return response.task_outputs
59+
return response
5660

5761
@property
5862
def client(self):
@@ -78,17 +82,23 @@ def _update(self):
7882
def get_definition(self) -> model_definition_interface.ModelDefinition:
7983
return self.resource.model_definition
8084

81-
def get_readme(self, silent: bool = False) -> str:
82-
return self.client.model_service.get_model_card(
85+
def get_readme(self, silent: bool = False) -> Optional[str]:
86+
response = self.client.model_service.get_model_card(
8387
self.resource.id,
8488
silent=silent,
85-
).readme
89+
)
90+
if response is not None:
91+
return response.readme
92+
return response
8693

87-
def get_state(self, silent: bool = False) -> model_interface.Model.State:
88-
return self.client.model_service.watch_model(
94+
def get_state(self, silent: bool = False):
95+
response = self.client.model_service.watch_model(
8996
self.resource.id,
9097
silent=silent,
91-
).state
98+
)
99+
if response is not None:
100+
return response.state
101+
return response
92102

93103
def deploy(self, silent: bool = False) -> model_interface.Model.State:
94104
self.client.model_service.deploy_model(

instill/resources/pipeline.py

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# pylint: disable=no-member,wrong-import-position,no-name-in-module
2-
from typing import Tuple, Union
2+
from typing import Optional, Tuple, Union
33

44
import grpc
55
from google.longrunning import operations_pb2
@@ -36,13 +36,15 @@ def __call__(
3636
self,
3737
task_inputs: list,
3838
silent: bool,
39-
) -> Tuple[list, pipeline_interface.TriggerMetadata]:
39+
) -> Optional[Tuple[list, pipeline_interface.TriggerMetadata]]:
4040
resp = self.client.pipeline_service.trigger_pipeline(
4141
self.resource.id,
4242
task_inputs,
4343
silent=silent,
4444
)
45-
return resp.outputs, resp.metadata
45+
if resp is not None:
46+
return resp.outputs, resp.metadata
47+
return resp
4648

4749
@property
4850
def client(self):
@@ -64,21 +66,27 @@ def _update(self):
6466
self.resource = self.client.pipeline_service.get_pipeline(name=self.resource.id)
6567

6668
def get_operation(self, operation: operations_pb2.Operation, silent: bool = False):
67-
return self.client.pipeline_service.get_operation(
69+
response = self.client.pipeline_service.get_operation(
6870
operation.name,
6971
silent=silent,
70-
).operation
72+
)
73+
if response is not None:
74+
return response.operation
75+
return response
7176

7277
def trigger_async(
7378
self,
7479
task_inputs: list,
7580
silent: bool = False,
7681
) -> operations_pb2.Operation:
77-
return self.client.pipeline_service.trigger_async_pipeline(
82+
response = self.client.pipeline_service.trigger_async_pipeline(
7883
self.resource.id,
7984
task_inputs,
8085
silent=silent,
81-
).operation
86+
)
87+
if response is not None:
88+
return response.operation
89+
return response
8290

8391
def get_recipe(self) -> pipeline_interface.Recipe:
8492
return self.resource.recipe

poetry.lock

Lines changed: 6 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)