From 0e8da77bc239494711cc5ace3253447f19d0fa55 Mon Sep 17 00:00:00 2001 From: jtsodapop <67922677+jtsodapop@users.noreply.github.com> Date: Mon, 28 Mar 2022 16:06:33 -0400 Subject: [PATCH 1/3] update to upsert_instructions method --- labelbox/schema/project.py | 45 ++++++++++++++------------------------ 1 file changed, 17 insertions(+), 28 deletions(-) diff --git a/labelbox/schema/project.py b/labelbox/schema/project.py index b971196d2..bc7059375 100644 --- a/labelbox/schema/project.py +++ b/labelbox/schema/project.py @@ -415,7 +415,6 @@ def upsert_instructions(self, instructions_file: str) -> None: ) frontend = self.labeling_frontend() - frontendId = frontend.uid if frontend.name != "Editor": logger.warning( @@ -428,35 +427,25 @@ def upsert_instructions(self, instructions_file: str) -> None: f"instructions_file must be a pdf or html file. Found {instructions_file}" ) - lfo = list(self.labeling_frontend_options())[-1] instructions_url = self.client.upload_file(instructions_file) - customization_options = self.ontology().normalized - customization_options['projectInstructions'] = instructions_url - option_id = lfo.uid - - self.client.execute( - """mutation UpdateFrontendWithExistingOptionsPyApi ( - $frontendId: ID!, - $optionsId: ID!, - $name: String!, - $description: String!, - $customizationOptions: String! + + query_str = """mutation setprojectinsructionsPyApi($projectId: ID!, $instructions_url: String!) { + setProjectInstructions( + where: {id: $projectId}, + data: {instructionsUrl: $instructions_url} ) { - updateLabelingFrontend( - where: {id: $frontendId}, - data: {name: $name, description: $description} - ) {id} - updateLabelingFrontendOptions( - where: {id: $optionsId}, - data: {customizationOptions: $customizationOptions} - ) {id} - }""", { - "frontendId": frontendId, - "optionsId": option_id, - "name": frontend.name, - "description": "Video, image, and text annotation", - "customizationOptions": json.dumps(customization_options) - }) + id + ontology { + id + options + } + } + }""" + + self.client.execute(query_str, { + 'projectId': self.uid, + 'instructions_url': instructions_url + }) def labeler_performance(self) -> PaginatedCollection: """ Returns the labeler performances for this Project. From 48e16345a1fd554bb38dea1a7e4381bba919bafc Mon Sep 17 00:00:00 2001 From: jtsodapop <67922677+jtsodapop@users.noreply.github.com> Date: Mon, 28 Mar 2022 17:33:47 -0400 Subject: [PATCH 2/3] update to test case --- tests/integration/test_project.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/tests/integration/test_project.py b/tests/integration/test_project.py index 8235e5d6c..db03d001d 100644 --- a/tests/integration/test_project.py +++ b/tests/integration/test_project.py @@ -137,9 +137,8 @@ def test_attach_instructions(client, project): project.setup(editor, empty_ontology) project.upsert_instructions('tests/integration/media/sample_pdf.pdf') - assert json.loads( - list(project.labeling_frontend_options()) - [-1].customization_options).get('projectInstructions') is not None + + assert project.ontology().normalized['projectInstructions'] is not None with pytest.raises(ValueError) as exc_info: project.upsert_instructions('/tmp/file.invalid_file_extension') From e1551ebde74982eee03869a22f4910219ff0c6c0 Mon Sep 17 00:00:00 2001 From: jtsodapop <67922677+jtsodapop@users.noreply.github.com> Date: Mon, 28 Mar 2022 17:34:27 -0400 Subject: [PATCH 3/3] update to test case --- tests/integration/test_project.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/integration/test_project.py b/tests/integration/test_project.py index db03d001d..62fce9f84 100644 --- a/tests/integration/test_project.py +++ b/tests/integration/test_project.py @@ -1,4 +1,5 @@ import json +import time import pytest import requests @@ -137,7 +138,7 @@ def test_attach_instructions(client, project): project.setup(editor, empty_ontology) project.upsert_instructions('tests/integration/media/sample_pdf.pdf') - + time.sleep(3) assert project.ontology().normalized['projectInstructions'] is not None with pytest.raises(ValueError) as exc_info: