Skip to content

Commit 41597e0

Browse files
author
Val Brodsky
committed
Add ProjectStageFilter validations
1 parent 360d78f commit 41597e0

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

libs/labelbox/src/labelbox/schema/search_filters.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
from enum import Enum
33
from typing import List, Literal, Union
44

5-
from labelbox.pydantic_compat import BaseModel
5+
from labelbox.pydantic_compat import BaseModel, validator
66
from labelbox.schema.labeling_service_status import LabelingServiceStatus
77
from labelbox.utils import format_iso_datetime
88

@@ -121,6 +121,16 @@ class ProjectStageFilter(BaseSearchFilter):
121121
operator: IdOperator
122122
values: List[LabelingServiceStatus]
123123

124+
@validator('values', pre=True)
125+
def validate_values(cls, values):
126+
disallowed_values = [LabelingServiceStatus.Missing]
127+
for value in values:
128+
if value in disallowed_values:
129+
raise ValueError(
130+
f"{value} is not a valid value for ProjectStageFilter")
131+
132+
return values
133+
124134

125135
class DateValue(BaseSearchFilter):
126136
"""

libs/labelbox/tests/unit/test_unit_search_filters.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
from labelbox.schema.labeling_service import LabelingServiceStatus
33
from labelbox.schema.search_filters import IntegerValue, RangeDateTimeOperatorWithSingleValue, RangeOperatorWithSingleValue, DateRange, RangeOperatorWithValue, DateRangeValue, DateValue, IdOperator, OperationType, OrganizationFilter, ProjectStageFilter, SharedWithOrganizationFilter, TagFilter, TaskCompletedCountFilter, TaskRemainingCountFilter, WorkforceRequestedDateFilter, WorkforceRequestedDateRangeFilter, WorkforceStageUpdatedFilter, WorkforceStageUpdatedRangeFilter, WorkspaceFilter, build_search_filter
44
from labelbox.utils import format_iso_datetime
5+
import pytest
56

67

78
def test_id_filters():
@@ -22,6 +23,19 @@ def test_id_filters():
2223
) == '[{operator: "is", values: ["clphb4vd7000cd2wv1ktu5cwa"], type: "organization_id"}, {operator: "is", values: ["clphb4vd7000cd2wv1ktu5cwa"], type: "shared_with_organizations"}, {operator: "is", values: ["clphb4vd7000cd2wv1ktu5cwa"], type: "workspace"}, {operator: "is", values: ["tag"], type: "tag"}, {operator: "is", values: ["REQUESTED"], type: "stage"}]'
2324

2425

26+
def test_stage_filter_with_invalid_values():
27+
with pytest.raises(
28+
ValueError,
29+
match="is not a valid value for ProjectStageFilter") as e:
30+
_ = [
31+
ProjectStageFilter(operator=IdOperator.Is,
32+
values=[
33+
LabelingServiceStatus.Requested,
34+
LabelingServiceStatus.Missing
35+
]),
36+
]
37+
38+
2539
def test_date_filters():
2640
local_time_start = datetime.strptime("2024-01-01", "%Y-%m-%d")
2741
local_time_end = datetime.strptime("2025-01-01", "%Y-%m-%d")

0 commit comments

Comments
 (0)