Skip to content

Commit 6e6266b

Browse files
whistlervbrodsky
andauthored
[AL-7595] Add data_row identifier validation for running foundry app (#1323)
Co-authored-by: Val Brodsky <vbrodsky@users.noreply.github.com>
1 parent a8217b2 commit 6e6266b

File tree

2 files changed

+44
-21
lines changed

2 files changed

+44
-21
lines changed

labelbox/schema/foundry/foundry_client.py

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
from typing import Union
22
from labelbox import exceptions
33
from labelbox.schema.foundry.app import App, APP_FIELD_NAMES
4-
from labelbox.schema.foundry.model import Model, MODEL_FIELD_NAMES
5-
from labelbox.schema.identifiables import DataRowIds, GlobalKeys
4+
from labelbox.schema.identifiables import DataRowIds, GlobalKeys, IdType
65
from labelbox.schema.task import Task
76

87

@@ -78,23 +77,20 @@ def run_app(self, model_run_name: str,
7877
data_rows: Union[DataRowIds, GlobalKeys], app_id: str) -> Task:
7978
app = self._get_app(app_id)
8079

81-
data_rows_query = self.client.build_catalog_query(data_rows)
82-
8380
params = {
8481
"modelId": str(app.model_id),
8582
"name": model_run_name,
8683
"classToSchemaId": app.class_to_schema_id,
8784
"inferenceParams": app.inference_params,
88-
"searchQuery": {
89-
"query": [data_rows_query],
90-
"scope": None
91-
},
9285
"ontologyId": app.ontology_id
9386
}
9487

88+
data_rows_key = "dataRowIds" if data_rows.id_type == IdType.DataRowId else "globalKeys"
89+
params[data_rows_key] = list(data_rows)
90+
9591
query = """
96-
mutation CreateModelJobPyApi($input: CreateModelJobInput!) {
97-
createModelJob(input: $input) {
92+
mutation CreateModelJobPyApi($input: CreateModelJobForDataRowsInput!) {
93+
createModelJobForDataRows(input: $input) {
9894
taskId
9995
__typename
10096
}
@@ -104,5 +100,5 @@ def run_app(self, model_run_name: str,
104100
response = self.client.execute(query, {"input": params})
105101
except Exception as e:
106102
raise exceptions.LabelboxError('Unable to run foundry app', e)
107-
task_id = response["createModelJob"]["taskId"]
103+
task_id = response["createModelJobForDataRows"]["taskId"]
108104
return Task.get_task(self.client, task_id)

tests/integration/test_foundry.py

Lines changed: 37 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,23 @@ def foundry_client(client):
1818
return FoundryClient(client)
1919

2020

21+
@pytest.fixture()
22+
def text_data_row(dataset, random_str):
23+
global_key = "https://storage.googleapis.com/lb-artifacts-testing-public/sdk_integration_test/sample-text-1.txt-{random_str}"
24+
task = dataset.create_data_rows([{
25+
"row_data":
26+
"https://storage.googleapis.com/lb-artifacts-testing-public/sdk_integration_test/sample-text-1.txt",
27+
"media_type":
28+
"TEXT",
29+
"global_key":
30+
global_key
31+
}])
32+
task.wait_till_done()
33+
dr = dataset.data_rows().get_one()
34+
yield dr
35+
dr.delete()
36+
37+
2138
@pytest.fixture()
2239
def ontology(client, random_str):
2340
object_features = [
@@ -108,13 +125,23 @@ def test_run_foundry_app_returns_model_run_id(foundry_client, data_row, app):
108125
assert model_run.uid == model_run_id
109126

110127

111-
def test_run_foundry_app_with_non_existent_data_rows(foundry_client, data_row,
112-
app, random_str):
113-
data_rows = lb.GlobalKeys([data_row.global_key, "non-existent-global-key"])
114-
task = foundry_client.run_app(
115-
model_run_name=f"test-app-with-wrong-key-{random_str}",
116-
data_rows=data_rows,
117-
app_id=app.id)
118-
task.wait_till_done()
119-
# The incorrect data row is filtered out and the task still completes with the correct data row
120-
assert task.status == 'COMPLETE'
128+
def test_run_foundry_with_invalid_data_row_id(foundry_client, app, random_str):
129+
invalid_datarow_id = 'invalid-global-key'
130+
data_rows = lb.GlobalKeys([invalid_datarow_id])
131+
with pytest.raises(lb.exceptions.LabelboxError) as exception:
132+
foundry_client.run_app(
133+
model_run_name=f"test-app-with-invalid-datarow-id-{random_str}",
134+
data_rows=data_rows,
135+
app_id=app.id)
136+
assert invalid_datarow_id in exception.value
137+
138+
139+
def test_run_foundry_with_invalid_global_key(foundry_client, app, random_str):
140+
invalid_global_key = 'invalid-global-key'
141+
data_rows = lb.GlobalKeys([invalid_global_key])
142+
with pytest.raises(lb.exceptions.LabelboxError) as exception:
143+
foundry_client.run_app(
144+
model_run_name=f"test-app-with-invalid-global-key-{random_str}",
145+
data_rows=data_rows,
146+
app_id=app.id)
147+
assert invalid_global_key in exception.value

0 commit comments

Comments
 (0)