-
Notifications
You must be signed in to change notification settings - Fork 68
[PTDT-1108] Added client method unarchive_root_schema_node #939
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
labelbox/client.py
Outdated
| Returns: | ||
| bool | ||
| """ | ||
| ontology_endpoint = self.rest_endpoint + "/ontologies/" + ontology_id + '/feature-schemas/' + root_feature_schema_id + '/unarchive' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please encode ontology_id and root_feature_schema_id using urllib.parse.quote
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
labelbox/client.py
Outdated
| ontology_endpoint, | ||
| headers=self.rest_endpoint_headers, | ||
| ) | ||
| if response.status_code == 200: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| if response.status_code == 200: | |
| if response.status_code == requests.codes.ok: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
labelbox/client.py
Outdated
| return response.json()['unarchived'] | ||
| else: | ||
| raise labelbox.exceptions.LabelboxError( | ||
| "Failed unarchive root feature schema node: ", response.text) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the convention other methods follow
| "Failed unarchive root feature schema node: ", response.text) | |
| "Failed unarchive root feature schema node, message: ", response.text) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
kkim-labelbox
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you add a test case for this function? Other than that, left a couple small comments!
labelbox/client.py
Outdated
| def unarchive_feature_schema_node(self, ontology_id: str, | ||
| root_feature_schema_id: str) -> bool: | ||
| """ | ||
| Returns true if the root feature schema node was successfully unarchived, false otherwise |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we specify in the docstring here that only root level feature schemas are unarchivable?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
labelbox/client.py
Outdated
| headers=self.headers, | ||
| ) | ||
| if response.status_code == requests.codes.ok: | ||
| return response.json()['unarchived'] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's probably fine to return None here, since it'll just return true when successfully unarchived anyway. Unless there's a case where unarchived = false
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It'll return false if the user passes in a root feature schema id that does not belong to the ontology.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the response is false, maybe we can just raise an exception then with an error message indicating that the unarchive was unsuccessful? I know the docstring specifies the behavior, but customers may not necessarily check for the output of this function, so it may be safer to throw an explicit message indicating the behavior
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
labelbox/client.py
Outdated
| ) | ||
| if response.status_code == requests.codes.ok: | ||
| unarchived = bool(response.json()['unarchived']) | ||
| if (unarchived == False): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You cna do:
if not unarchived
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
actually I would just do
if not bool(response.json()['unarchived']):
raise labelbox.exceptions.LabelboxError(
"Failed unarchive the feature schema.")
return
and set the function return type to None
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How to test:
Given a valid API key that owns the valid ontology and root feature schema node expect
TrueUse a valid api key for a user in another org. Attempt to unarchive the root feature schema node belonging to another org. Expect to get a "404" response.
https://www.loom.com/share/379eaebf4f5c483fa0fc0ca6656475d9