Skip to content

Commit 255c83e

Browse files
authored
Vb/remove ontology disconnect plt 1308 (#1763)
1 parent a18c13b commit 255c83e

File tree

5 files changed

+29
-7
lines changed

5 files changed

+29
-7
lines changed

libs/labelbox/src/labelbox/exceptions.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ def __init__(self, db_object_type=None, params=None, message=None):
4444
super().__init__(message)
4545
else:
4646
super().__init__("Resource '%s' not found for params: %r" %
47-
(db_object_type.type_name(), params))
47+
(db_object_type.type_name(), params))
4848
self.db_object_type = db_object_type
4949
self.params = params
5050

@@ -144,6 +144,11 @@ class OperationNotAllowedException(Exception):
144144
pass
145145

146146

147+
class OperationNotSupportedException(Exception):
148+
"""Raised when sdk does not support requested operation"""
149+
pass
150+
151+
147152
class ConfidenceNotSupportedException(Exception):
148153
"""Raised when confidence is specified for unsupported annotation type"""
149154

libs/labelbox/src/labelbox/orm/db_object.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1+
from dataclasses import dataclass
12
from datetime import datetime, timezone
23
from functools import wraps
34
import logging
45
import json
56

67
from labelbox import utils
7-
from labelbox.exceptions import InvalidQueryError, InvalidAttributeError
8+
from labelbox.exceptions import InvalidQueryError, InvalidAttributeError, OperationNotSupportedException
89
from labelbox.orm import query
910
from labelbox.orm.model import Field, Relationship, Entity
1011
from labelbox.pagination import PaginatedCollection
@@ -123,6 +124,7 @@ def __init__(self, source, relationship, value=None):
123124
self.supports_sorting = True
124125
self.filter_on_id = True
125126
self.value = value
127+
self.config = relationship.config
126128

127129
def __call__(self, *args, **kwargs):
128130
""" Forwards the call to either `_to_many` or `_to_one` methods,
@@ -191,6 +193,10 @@ def connect(self, other):
191193

192194
def disconnect(self, other):
193195
""" Disconnects source object of this manager from the `other` object. """
196+
if not self.config.disconnect_supported:
197+
raise OperationNotSupportedException(
198+
"Disconnect is not supported for this relationship")
199+
194200
query_string, params = query.update_relationship(
195201
self.source, other, self.relationship, "disconnect")
196202
self.source.client.execute(query_string, params)

libs/labelbox/src/labelbox/orm/model.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from dataclasses import dataclass
12
from enum import Enum, auto
23
from typing import Dict, List, Union, Any, Type, TYPE_CHECKING
34

@@ -219,6 +220,10 @@ class Relationship:
219220
220221
"""
221222

223+
@dataclass
224+
class Config:
225+
disconnect_supported: bool = True
226+
222227
class Type(Enum):
223228
ToOne = auto()
224229
ToMany = auto()
@@ -238,12 +243,14 @@ def __init__(self,
238243
name=None,
239244
graphql_name=None,
240245
cache=False,
241-
deprecation_warning=None):
246+
deprecation_warning=None,
247+
config=Config()):
242248
self.relationship_type = relationship_type
243249
self.destination_type_name = destination_type_name
244250
self.filter_deleted = filter_deleted
245251
self.cache = cache
246252
self.deprecation_warning = deprecation_warning
253+
self.config = config
247254

248255
if name is None:
249256
name = utils.snake_case(destination_type_name) + (

libs/labelbox/src/labelbox/schema/project.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,9 @@ class Project(DbObject, Updateable, Deletable):
132132
# Relationships
133133
created_by = Relationship.ToOne("User", False, "created_by")
134134
organization = Relationship.ToOne("Organization", False)
135-
labeling_frontend = Relationship.ToOne("LabelingFrontend")
135+
labeling_frontend = Relationship.ToOne(
136+
"LabelingFrontend",
137+
config=Relationship.Config(disconnect_supported=False))
136138
labeling_frontend_options = Relationship.ToMany(
137139
"LabelingFrontendOptions", False, "labeling_frontend_options")
138140
labeling_parameter_overrides = Relationship.ToMany(

libs/labelbox/tests/integration/test_labeling_frontend.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1-
from labelbox import LabelingFrontend
21
import pytest
32

3+
from labelbox import LabelingFrontend
4+
from labelbox.exceptions import OperationNotSupportedException
5+
46

57
def test_get_labeling_frontends(client):
68
filtered_frontends = list(
@@ -18,5 +20,5 @@ def test_labeling_frontend_connecting_to_project(project):
1820
project.labeling_frontend.connect(default_labeling_frontend)
1921
assert project.labeling_frontend() == default_labeling_frontend
2022

21-
project.labeling_frontend.disconnect(default_labeling_frontend)
22-
assert project.labeling_frontend() == None
23+
with pytest.raises(OperationNotSupportedException):
24+
project.labeling_frontend.disconnect(default_labeling_frontend)

0 commit comments

Comments
 (0)