Skip to content

Vb/remove ontology disconnect plt 1308 #1763

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

Merged
merged 2 commits into from
Aug 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion libs/labelbox/src/labelbox/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def __init__(self, db_object_type=None, params=None, message=None):
super().__init__(message)
else:
super().__init__("Resource '%s' not found for params: %r" %
(db_object_type.type_name(), params))
(db_object_type.type_name(), params))
self.db_object_type = db_object_type
self.params = params

Expand Down Expand Up @@ -144,6 +144,11 @@ class OperationNotAllowedException(Exception):
pass


class OperationNotSupportedException(Exception):
"""Raised when sdk does not support requested operation"""
pass


class ConfidenceNotSupportedException(Exception):
"""Raised when confidence is specified for unsupported annotation type"""

Expand Down
8 changes: 7 additions & 1 deletion libs/labelbox/src/labelbox/orm/db_object.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
from dataclasses import dataclass
from datetime import datetime, timezone
from functools import wraps
import logging
import json

from labelbox import utils
from labelbox.exceptions import InvalidQueryError, InvalidAttributeError
from labelbox.exceptions import InvalidQueryError, InvalidAttributeError, OperationNotSupportedException
from labelbox.orm import query
from labelbox.orm.model import Field, Relationship, Entity
from labelbox.pagination import PaginatedCollection
Expand Down Expand Up @@ -123,6 +124,7 @@ def __init__(self, source, relationship, value=None):
self.supports_sorting = True
self.filter_on_id = True
self.value = value
self.config = relationship.config

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

def disconnect(self, other):
""" Disconnects source object of this manager from the `other` object. """
if not self.config.disconnect_supported:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code should be below docstring

raise OperationNotSupportedException(
"Disconnect is not supported for this relationship")

query_string, params = query.update_relationship(
self.source, other, self.relationship, "disconnect")
self.source.client.execute(query_string, params)
Expand Down
9 changes: 8 additions & 1 deletion libs/labelbox/src/labelbox/orm/model.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from dataclasses import dataclass
from enum import Enum, auto
from typing import Dict, List, Union, Any, Type, TYPE_CHECKING

Expand Down Expand Up @@ -219,6 +220,10 @@ class Relationship:

"""

@dataclass
class Config:
disconnect_supported: bool = True

class Type(Enum):
ToOne = auto()
ToMany = auto()
Expand All @@ -238,12 +243,14 @@ def __init__(self,
name=None,
graphql_name=None,
cache=False,
deprecation_warning=None):
deprecation_warning=None,
config=Config()):
self.relationship_type = relationship_type
self.destination_type_name = destination_type_name
self.filter_deleted = filter_deleted
self.cache = cache
self.deprecation_warning = deprecation_warning
self.config = config

if name is None:
name = utils.snake_case(destination_type_name) + (
Expand Down
4 changes: 3 additions & 1 deletion libs/labelbox/src/labelbox/schema/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,9 @@ class Project(DbObject, Updateable, Deletable):
# Relationships
created_by = Relationship.ToOne("User", False, "created_by")
organization = Relationship.ToOne("Organization", False)
labeling_frontend = Relationship.ToOne("LabelingFrontend")
labeling_frontend = Relationship.ToOne(
"LabelingFrontend",
config=Relationship.Config(disconnect_supported=False))
labeling_frontend_options = Relationship.ToMany(
"LabelingFrontendOptions", False, "labeling_frontend_options")
labeling_parameter_overrides = Relationship.ToMany(
Expand Down
8 changes: 5 additions & 3 deletions libs/labelbox/tests/integration/test_labeling_frontend.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
from labelbox import LabelingFrontend
import pytest

from labelbox import LabelingFrontend
from labelbox.exceptions import OperationNotSupportedException


def test_get_labeling_frontends(client):
filtered_frontends = list(
Expand All @@ -18,5 +20,5 @@ def test_labeling_frontend_connecting_to_project(project):
project.labeling_frontend.connect(default_labeling_frontend)
assert project.labeling_frontend() == default_labeling_frontend

project.labeling_frontend.disconnect(default_labeling_frontend)
assert project.labeling_frontend() == None
with pytest.raises(OperationNotSupportedException):
project.labeling_frontend.disconnect(default_labeling_frontend)
Loading