Skip to content

Commit

Permalink
feat: Add backing_item_uuid to the LRv2 as an optional attribute (#808)
Browse files Browse the repository at this point in the history
* feat: Add backing_item_uuid to the LRv2 as an optional attribute

* fix: Ensure that deserialisation is backwards compatible. Tests are great :)

* fix: Use current backing item uuid after initialise_labels
  • Loading branch information
Jim-Encord authored Dec 3, 2024
1 parent 1bab699 commit 648cab1
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 3 deletions.
18 changes: 17 additions & 1 deletion encord/objects/ontology_labels_impl.py
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,19 @@ def audio_num_channels(self) -> Optional[int]:
"""
return self._label_row_read_only_data.audio_num_channels

@property
def backing_item_uuid(self) -> Optional[str]:
"""
Returns the unique identifier (UUID) for the backing storage item associated with this label row.
The backing item UUID represents the storage reference for the data linked to the row.
While it is always included in server responses, it is marked as optional for backward compatibility with earlier versions.
Returns:
Optional[str]: The backing storage item id or None if not found.
"""
# TODO: Mark required in 0.2 release
return self._label_row_read_only_data.backing_item_uuid

@property
def priority(self) -> Optional[float]:
"""
Expand Down Expand Up @@ -1576,6 +1589,7 @@ class LabelRowReadOnlyData:
last_edited_at: Optional[datetime]
data_hash: str
data_type: DataType
backing_item_uuid: Optional[str]
label_status: LabelStatus
annotation_task_status: Optional[AnnotationTaskStatus]
workflow_graph_node: Optional[WorkflowGraphNode]
Expand All @@ -1595,7 +1609,7 @@ class LabelRowReadOnlyData:
data_link: Optional[str]
priority: Optional[float]
file_type: Optional[str]
client_metadata: Optional[dict]
client_metadata: Optional[Dict[str, Any]]
images_data: Optional[List[LabelRowV2.LabelRowReadOnlyDataImagesDataEntry]]
branch_name: str
frame_level_data: Dict[int, LabelRowV2.FrameLevelImageGroupData] = field(default_factory=dict)
Expand Down Expand Up @@ -1947,6 +1961,7 @@ def _parse_label_row_metadata(self, label_row_metadata: LabelRowMetadata) -> Lab
client_metadata=label_row_metadata.client_metadata,
file_type=label_row_metadata.file_type,
is_valid=label_row_metadata.is_valid,
backing_item_uuid=label_row_metadata.backing_item_uuid,
)

def _parse_label_row_dict(self, label_row_dict: dict) -> LabelRowReadOnlyData:
Expand Down Expand Up @@ -2033,6 +2048,7 @@ def _parse_label_row_dict(self, label_row_dict: dict) -> LabelRowReadOnlyData:
images_data=label_row_dict.get("images_data", self._label_row_read_only_data.images_data),
file_type=label_row_dict.get("file_type", None),
is_valid=bool(label_row_dict.get("is_valid", True)),
backing_item_uuid=label_row_dict.get("backing_item_uuid", self.backing_item_uuid),
)

def _parse_labels_from_dict(self, label_row_dict: dict):
Expand Down
11 changes: 9 additions & 2 deletions encord/orm/label_row.py
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,8 @@ class LabelRowMetadata(Formatter):
"""Only available for certain read requests"""
is_valid: bool = True

backing_item_uuid: Optional[str] = None

@classmethod
def from_dict(cls, json_dict: Dict) -> LabelRowMetadata:
created_at = json_dict.get("created_at", None)
Expand Down Expand Up @@ -335,6 +337,7 @@ def from_dict(cls, json_dict: Dict) -> LabelRowMetadata:
file_type=json_dict.get("file_type"),
is_valid=bool(json_dict.get("is_valid", True)),
branch_name=json_dict["branch_name"],
backing_item_uuid=json_dict.get("backing_item_uuid", None),
)

@classmethod
Expand Down Expand Up @@ -393,6 +396,7 @@ class LabelRowMetadataDTO(BaseDTO):
data_title: str
data_type: str
data_link: Optional[str] = None

"""Can be `None` for label rows of image groups or DICOM series."""
label_status: LabelStatus
"""Can be `None` for TMS2 projects"""
Expand All @@ -418,12 +422,14 @@ class LabelRowMetadataDTO(BaseDTO):

priority: Optional[float] = None
"""Only available for not complete tasks"""
client_metadata: Optional[dict] = None
images_data: Optional[list] = None
client_metadata: Optional[Dict[str, Any]] = None
images_data: Optional[List[Any]] = None
file_type: Optional[str] = None
"""Only available for certain read requests"""
is_valid: bool = True

backing_item_uuid: Optional[str] = None


def label_row_metadata_dto_to_label_row_metadata(label_row_metadata_dto: LabelRowMetadataDTO) -> LabelRowMetadata:
return LabelRowMetadata(
Expand Down Expand Up @@ -455,4 +461,5 @@ def label_row_metadata_dto_to_label_row_metadata(label_row_metadata_dto: LabelRo
file_type=label_row_metadata_dto.file_type,
is_valid=label_row_metadata_dto.is_valid,
branch_name=label_row_metadata_dto.branch_name,
backing_item_uuid=label_row_metadata_dto.backing_item_uuid,
)

0 comments on commit 648cab1

Please sign in to comment.